Linux上安装MySQL8.0.15后,无法远程连接问题。
远程连接MySQL时报错
一、查看Mysql是否开启可以远程访问的权限
1.登录mysql机器
mysql -u root -p
2.切换到Mysql数据库
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql>
3.查看是否运行远程访问
可以看到第一行root 用户的host为localhost,要远程访问,需要将它改成%
mysql> select host,user,plugin from user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
| localhost | root | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)
mysql>
4.将host改为%
mysql> update user set host='%' where user ='root';
Query OK, 1 row affected (0.07 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select host,user,plugin from user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | root | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)
mysql>
5.刷新权限
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.10 sec)
mysql>
现在有权限访问了,但是校验方式又有了问题
2059 - Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(../Frameworks/caching_sha2_password.so, 2): image not found
二、更改连接的密码校验方式
caching_sha2_password
加密方式在远程访问时候不支持。
需要改成:mysql_native_password
1.更改连接方式
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.09 sec)
mysql> select host,user,plugin from user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | root | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)
mysql>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
2.刷新权限
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.04 sec)
mysql>
3.远程连接
好了,可以愉快的开发了。