解决java.sql.SQLException: Unable to load authentication plugin ‘caching_sha2_password‘.

问题

在更新自有产品的子模块商城系统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-hosts

4、如果有SUPER权限,执行

FLUSH HOSTS;

5、如上因故不行,执行命令配置更多的连接错误尝试

SET GLOBAL max_connect_errors = 1000;

也可以通过配置my.cnf


[mysqld]
max_connect_errors=1000

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李景琰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值