天天看点

MySQL - 2059 - Authentication plugin ‘caching_sha2_password‘ cannot be loaded

问题报错

2059 - authentication plugin 'caching_sha2_password' cannot be loaded...

分析原因

MySQL - 2059 - Authentication plugin ‘caching_sha2_password‘ cannot be loaded

这个报错,中文意思就是:权限插件 caching_sha2_password 不能被加载

通过查阅 MySQL 的官方参考文档,我们看到这样的一段描述

  • In MySQL 5.7, libmysqlclient uses as its default choice either mysql_native_password or the plugin specified through the MYSQL_DEFAULT_AUTH option for mysql_options().
  • When a 5.7 client tries to connect to an 8.0 server, the server specifies caching_sha2_password as its default authentication plugin, but the client still sends credential details per either mysql_native_password or whatever is specified through MYSQL_DEFAULT_AUTH.

从这里,我们就明白了

  • 8.0 以前的默认身份验证插件是 mysql_native_password
  • 8.0 以后的默认身份验证插件是 caching_sha2_password

这里会报错的原因在上面也提到了:5.7 的客户端去连接 8.0 的服务端,因为默认的身份验证插件不同,故会造成插件不能加载的错误

说明一下:目前大多数的 MySQL 客户端都还没有升级为 8.0 的认证方式,故像 Navicat、Sequel Pro、SQLyog 等这些常用的连接工具,都有可能出现这个问题

解决方案

将 MySQL 8.0 的身份认证插件改回为 mysql_native_password

#登录
mysql -uroot -ppassword 
 
#选择数据库
use mysql; 
 
# 注意:如果是远程连接,请将'localhost'换成'%'
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的数据库密码';
 
#刷新权限
FLUSH PRIVILEGES;