docker容器中,Navicat Premium 12连接MySQL数据库出现Authentication plugin ‘caching_sha2_password‘ cannot be load

前言

在docker容器中,Navicat Premium 12连接MySQL8.0数据库出现Authentication plugin ‘caching_sha2_password’ cannot be loaded的解决方案,

由于docker上pull的mysql为最新的,为Mysql8.0,而mysql8.0的验证不一样。所以,用远程连接的时候会有下面的错误

docker容器中,Navicat Premium 12连接MySQL数据库出现Authentication plugin ‘caching_sha2_password‘ cannot be load
原因是docker mysql为最新的,更换了新的身份验证插件(caching_sha2_password), 原来的身份验证插件为(mysql_native_password)

解决方案

  • 首先进入容器,登录mysql
    命令如下

#进入容器
docker exec -it mysql8 /bin/bash
#登录
mysql mysql -uroot -p;
#切换数据库
use mysql

如图
docker容器中,Navicat Premium 12连接MySQL数据库出现Authentication plugin ‘caching_sha2_password‘ cannot be load

  • 查看user表的情况
    命令如下:

select user,host,plugin,authentication_string from user;
#输入分号才会显示结果

如图:
docker容器中,Navicat Premium 12连接MySQL数据库出现Authentication plugin ‘caching_sha2_password‘ cannot be load
从图中可以看出需要修改的红色部分

进行修改

修改命令如下:

#修改加密规则 (注意:通过上图,如果host=localhost的话,下面的%改成localhost)
alter USER ‘dev’@’%’ identified BY ‘password’ PASSWORD EXPIRE NEVER;
#更新一下用户的密码 (注意:通过上图,如果host=localhost的话,下面的%改成localhost)
alter USER ‘dev’@’%’ identified WITH mysql_native_password BY ‘password’ ;
#再重置下密码:(注意:通过上图,如果host=localhost的话,下面的%改成localhost)
alter user ‘dev’@’%’ identified by ‘dev123’;
#刷新权限 flush privileges;

如下图为执行命令情况

docker容器中,Navicat Premium 12连接MySQL数据库出现Authentication plugin ‘caching_sha2_password‘ cannot be load
查看结果
通过输入:

select user,host,plugin,authentication_string from user;

docker容器中,Navicat Premium 12连接MySQL数据库出现Authentication plugin ‘caching_sha2_password‘ cannot be load
由上图可以知道,已经改回来了。root账号,一样的修改方式,这样再连接就正常了

docker容器中,Navicat Premium 12连接MySQL数据库出现Authentication plugin ‘caching_sha2_password‘ cannot be load

写在最后

当然,可以修改配置文件,如下
修改配置文件

default_authentication_plugin=caching_sha2_password 修改为:

default_authentication_plugin=mysql_native_password

具体实现方式,可以自己去操作一下。

好了,如果觉得可以帮助你,请记得关注我哦