Centos7.9通过yum安装MySQL8.5,并且修改密码实现远程登陆

请注意:MySQL5.6之后密码规则发生变化,需要特殊字符+字母+数字的密码

1.配置仓库:

[root@localhost ~]# yum install https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm -y

2.yum安装:

[root@localhost ~]# yum install mysql-community-server -y

1.出现报错:

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

2.解决方法:

[root@localhost ~]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
[root@localhost ~]# yum -y install mysql-community-server

3.重启服务:

[root@localhost ~]# systemctl enable mysqld;systemctl restart mysqld

4.关闭防火墙:

[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.

5.查看临时密码:

[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

6.登陆:

[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

7.更新root用户密码:

mysql> alter user 'root'@'localhost' identified with mysql_native_password by '密码';
Query OK, 0 rows affected (0.00 sec)

8.刷新权限:

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

9.查看用户信息表,plugin值为mysql_native_password的用户才可以被登录;即caching_sha2_password不行

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)

10.允许远程登录:

mysql> update mysql.user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

11.刷新权限:

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

12.查看用户信息表,plugin值为mysql_native_password的用户才可以被登录;即caching_sha2_password不行

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)

13.重启数据库:

[root@localhost ~]# systemctl restart mysqld

最后,远程登陆

猜你喜欢

转载自blog.csdn.net/qq_56776641/article/details/134362478