在局域网中使用Docker远程连接数据库报错:
2059 - Authentication plugin ‘xxxxxxx’ cannot be loaded:XXXXXX (无法加载身份验证插件)
在这里插入图片描述
原因:mysql8 之前的版本中加密规则是mysql_native_password,而在mysql8之后,加密规则是caching_sha2_password

解决办法:更改加密规则

1、查看当前运行的docker容器

[root@localhost ~]# docker ps
CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS                    PORTS                      
                         NAMES
4b789c107052        mysql/mysql-server   "/entrypoint.sh mysq…"   29 minutes ago      Up 29 minutes (healthy)   0.0.0.0:32769->3306/tcp, 0.
0.0.0:32768->33060/tcp   mysql03
010a32224776        mysql/mysql-server   "/entrypoint.sh mysq…"   40 minutes ago      Up 40 minutes (healthy)   0.0.0.0:3306->3306/tcp, 330
60/tcp                   mysql02

2、在mysql02容器中以root用户登录MySQL

[root@localhost ~]# docker exec -it mysql02 mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 92
Server version: 8.0.17 MySQL Community Server - GPL

选择mysql数据库

mysql> use mysql;

3、更改加密方式

mysql> ALTER USER 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.08 sec)

4、更新用户密码

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.02 sec)

5、刷新权限

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

之后再次连接就能成功了。

参考文献:
李帆1998的博客 Navicat 连接MySQL 8.0.11 出现2059错误

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐