Navicat连不上mysql8

今天使用navicat连接mysql8,发现错误连连

错误1:1130-Host '192.168.50.2' is not allowed to connect to this MySQL server

错误2:2059-Authentication plugin 'caching_sha2_password' cannot be loaded:The specified module could not be found

登录mysql,并切换数据库

mysql -u root -proot

use mysql;

mysql 数据库中存储了一张 MySQL 用户的 user 表,可以查看当前 root 用户的相关信息

select host, user, plugin from user where user = 'root';

表格中有以下信息:

host: 允许用户登录的 ip ‘位置’ % 表示可以远程;

user: 当前数据库的用户名;

authentication_string: 用户密码(在mysql 5.7.9以后废弃了password字段和password()函数);

plugin: 密码加密方式;

1,首先要修改用户可从外网访问的权限

mysql> update user set host = '%' where user = 'root';

mysql> FLUSH PRIVILEGES;

这时,错误1就被解决了。

2,更改加密方式,mysql8引入了新特性 caching_sha2_password;老客户端不支持,改为mysql_native_password 方式;

ALTER USER 'username'@'%' IDENTIFIED WITH mysql_native_password BY 'password';

这时,错误2就被解决了。

注意:用update方式修改密码策略会导致用户丢失。要删掉重建。

转载于:https://www.cnblogs.com/guanghe/p/10186733.html