问题
在更新自有产品的子模块商城系统yangtze-shop的版本时,报错
java.sql.SQLException: Unable to load authentication plugin 'caching_sha2_password'。

原因
这是因为咱以前的centos转成debian使用的 mysql版本是8.0+,mysql 8.0 默认使用 caching_sha2_password 身份验证机制。是从原来mysql 5.7的 mysql_native_password 更改为mysql 8.0的caching_sha2_password,而打包的项目使用的MySQL connector的版本比较低,所以导致报错(版本冲突)。
问题解决
1.修改数据库的配置(推荐)
2. 降低Mysql版本
3.升级项目中Mysql版本
方案1。
1、登录Linux服务器。
2、登录MySQL命令:mysql -uroot -p,输入登录密码
3、查询:select host,user,plugin from mysql.user;

4、修改plugin。
alter user 'root'@'localhost' identified by '密码' password expire never;
alter user 'root'@'localhost' identified with mysql_native_password by '密码';alter user 'root'@'%' identified by '密码' password expire never;
alter user 'root'@'%' identified with mysql_native_password by '密码';
flush privileges;
也可以直接修改my.cnf,重启。
[mysqld]
default_authentication_plugin=mysql_native_password
方案3。
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.22</version>
</dependency>
连带问题:Unable to load authentication plugin 'caching_sha2_password'
如果java.sql.SQLException: Unable to load authentication plugin 'caching_sha2_password'。报错未关闭程序,报错过多,多次连接失败导致MySQL服务器出于安全考虑将该主机阻止。重启项目报错:
is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'"
问题解决
1、登录Linux服务器。
2、登录MySQL命令:mysql -uroot -p,输入登录密码
3、重置连接错误计数器,解锁被阻止的主机
mysqladmin -u root -p flush-hosts4、如果有SUPER权限,执行
FLUSH HOSTS;5、如上因故不行,执行命令配置更多的连接错误尝试
SET GLOBAL max_connect_errors = 1000;也可以通过配置my.cnf
[mysqld] max_connect_errors=1000
1740

被折叠的 条评论
为什么被折叠?



