MySQL安装
1、下载软件包:mysql-8.0.15-1.el7.x86_64.rpm-bundle.tar
2、将软件包通过moba上传到linux系统/usr/local/soft/目录下
3、解压软件包
cd /usr/local/soft/ tar -xvf mysql-8.0.15-1.el7.x86_64.rpm-bundle.tar4、卸载系统自带mariadb
rpm -qa | grep mariadb yum -y remove mariadb-libs-5.5.52-1.el7.x86_645、下载依赖包(可直接全部复制粘贴,批量执行)
yum -y install openssl-devel perl-JSON yum install -y libaio.x86_64 libaio-devel.x86_64 yum install -y openssl-devel.x86_64 openssl.x86_64 yum install -y perl.x86_64 perl-devel.x86_64 yum install -y perl-JSON.noarch yum install -y autoconf yum install net-tools –y yum -y install numactl6、顺序安装mysql(可直接全部复制粘贴,批量执行)
rpm -ivh mysql-community-common-8.0.15-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-8.0.15-1.el7.x86_64.rpm rpm -ivh mysql-community-client-8.0.15-1.el7.x86_64.rpm rpm -ivh mysql-community-server-8.0.15-1.el7.x86_64.rpm rpm -ivh mysql-community-devel-8.0.15-1.el7.x86_64.rpm安装完默认是mysql用户、用户组和权限
chown -R mysql:mysql /var/lib/mysql/7、重启mysql服务
systemctl restart mysqld.service systemctl status mysqld.service若启动失败查看:
tail -n 100 /var/log/mysqld.log8、查看密码
cat /var/log/mysqld.log | grep password或
cd /var/log/ cat mysqld.log9、数据库登陆
mysql -u root -p输入第八步中的密码进行登陆
10、设置登陆密码复杂度
set global validate_password.length=4; set global validate_password.policy=0;11、修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123'; flush privileges;12、开放所有IP都能访问
use mysql; select host, user, authentication_string, plugin from user; CREATE USER 'root'@'%' IDENTIFIED BY 'root123'; grant all privileges ON *.* to 'root'@'%' with grant option; flush privileges;13、修改加密方式
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root123'; select host, user, authentication_string, plugin from user;14、重启数据库
quit systemctl restart mysqld.service或:
systemctl start mysqld设置开机自启动
systemctl enable mysqld.service15、远程navicat连接测试
16、其它配置
初始状态
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html [mysqld] # # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # # Remove the leading "# " to disable binary logging # Binary logging captures changes between backups and is enabled by # default. It's default setting is log_bin=binlog # disable_log_bin # # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M # # Remove leading # to revert to previous value for default_authentication_plugin, # this will increase compatibility with older clients. For background, see: # https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin # default-authentication-plugin=mysql_native_password datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid其它配置参考如下
vi /etc/my.cnf
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [mysqld] port=3323 #skip-grant-tables # # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 lower_case_table_names=1 sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION max_allowed_packet = 500M wait_timeout=86400重置密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'asdfadfbEVG'; ALTER USER 'root'@'%' IDENTIFIED BY 'asdfadfbEVG'; flush privileges;FAQ
1、错误:依赖检测失败:
libcrypto.so.10()(64bit) 被 mysql-community-libs-8.0.15-1.el7.x86_64 需要
遇到类似的错误的话,可以试试在rpm安装命令后添加
--nodeps --force如:
rpm -ivh mysql-community-common-8.0.15-1.el7.x86_64.rpm --nodeps --force rpm -ivh mysql-community-libs-8.0.15-1.el7.x86_64.rpm --nodeps --force rpm -ivh mysql-community-client-8.0.15-1.el7.x86_64.rpm --nodeps --force rpm -ivh mysql-community-server-8.0.15-1.el7.x86_64.rpm --nodeps --force rpm -ivh mysql-community-devel-8.0.15-1.el7.x86_64.rpm --nodeps --force2、云服务器上数据库总是恢复,可在配置文件中添加
innodb_force_recovery = 13、让表忽略大小写
由于8.0没法设置参数后重启(失败),所以必须删掉老库,重新启动才行。
切记:;本步骤要删掉老库所有资料,如果是数据库当前有用,请做好备份,再进行操作。
systemctl stop mysqld #默认数据在这里 cd /var/lib/mysql rm -rf *编辑配置文件
vim /etc/my.cnf配置文件中添加
symbolic-links=0 lower_case_table_names=1 sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION max_allowed_packet = 500M wait_timeout=86400重启数据库
systemctl restart mysqld此时由于重新初始化数据库,老密码已经没有了,系统自动初始化一个随机新密码
sudo grep 'temporary password' /var/log/mysqld.log还有一种,就是最新版的MYSQL8 默认root没密码, 直接mysql进去
重复上面10-13步骤
然后验证配置结果
show variables like '%case_table%';重新远程连接如下:
参考地址:
Mysql8忽略大小写的解决方案.240105 - 中国的Amadeus - 博客园