Navicat连不上mysql8

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

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

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

登陆mysql,并切换数据库函数

  mysql -u root -prootthis

  use mysql;加密

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

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

表格中有如下信息:blog

  host: 容许用户登陆的 ip ‘位置’ % 表示能够远程;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方式修改密码策略会致使用户丢失。要删掉重建。