请注意:MySQL5.6之后密码规则发生变化,需要特殊字符+字母+数字的密码
[root@localhost ~]# yum install https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm -y
[root@localhost ~]# yum install mysql-community-server -y
Public key for mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm is not installed
Failing package is: mysql-community-client-plugins-8.0.35-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[root@localhost ~]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
[root@localhost ~]# yum -y install mysql-community-server
[root@localhost ~]# systemctl enable mysqld;systemctl restart mysqld
[root@localhost ~]# systemctl disable firewalld;systemctl stop firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
2023-11-12T07:59:48.012101Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: sY_R1hx1UOIp
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.35
mysql> alter user 'root'@'localhost' identified with mysql_native_password by '密码';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host,plugin from mysql.user;
+------------------+-----------+-----------------------+
| user | host | plugin |
+------------------+-----------+-----------------------+
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session | localhost | caching_sha2_password |
| mysql.sys | localhost | caching_sha2_password |
| root | localhost | mysql_native_password |
+------------------+-----------+-----------------------+
4 rows in set (0.00 sec)
mysql> update mysql.user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host,plugin from mysql.user;
+------------------+-----------+-----------------------+
| user | host | plugin |
+------------------+-----------+-----------------------+
| root | % | mysql_native_password |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session | localhost | caching_sha2_password |
| mysql.sys | localhost | caching_sha2_password |
+------------------+-----------+-----------------------+
4 rows in set (0.00 sec)
[root@localhost ~]# systemctl restart mysqld
最后,远程登陆