java.sql.SQLException: Unable to load authentication plugin 'caching_sha2_password'.避坑指南

最近遇到了 java.sql.SQLException: Unable to load authentication plugin 'caching_sha2_password'.这个报错。

再此分享,希望能够对其他人有帮助,

主要原因8.x版本的验证模块和之前版本不同:

5.x版本是:default_authentication_plugin=mysql_native_password

8.x版本就是:default_authentication_plugin=caching_sha2_password

网上的主要解决方案是:

1 修改mysql的配置文件为旧的模块

2 运行命令将某个用户的验证模块改为旧版的模块

但是我更建议用另外一种方案,更新mysql驱动的jar版本,可以修改为8.0.11版本

因为MySQL的版本升级就是为了更加安全,不应该为了迁就旧的驱动而修改验证插件。

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.11</version>
</dependency>

猜你喜欢

转载自blog.csdn.net/w605283073/article/details/88096598