Caused by: java.sql.SQLException: Unable to load authentication plugin 'caching_sha2_password'.

 项目启动报错,错误信息如下:

Caused by: java.sql.SQLException: Unable to load authentication plugin ‘caching_sha2_password‘.
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:868) ~[mysql-connector-java-5.1.43.jar:5.1.43]
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:864) ~[mysql-connector-java-5.1.43.jar:5.1.43]
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1746) ~[mysql-connector-java-5.1.43.jar:5.1.43]
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1226) ~[mysql-connector-java-5.1.43.jar:5.1.43]
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2198) ~[mysql-connector-java-5.1.43.jar:5.1.43]
    at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2045) ~[mysql-connector-java-5.1.43.jar:5.1.43]
    ... 62 common frames omitted

 

环境信息:

  mysql 8.0.22

错误原因:

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

5.x版本是:default_authentication_plugin=mysql_native_password

8.x版本是:default_authentication_plugin=caching_sha2_password

解决方法:

升级mysql 驱动

<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>8.0.22</version>
  <!--<version>5.1.22</version>-->
</dependency>

 注意升级完驱动需要修改

8.x:  driver-class-name=com.mysql.cj.jdbc.Driver
5.x:  driver-class-name=com.mysql.jdbc.Driver

Caused by: java.sql.SQLException: Unable to load authentication plugin 'caching_sha2_password'.

上一篇:.net core 中使用Log4net输出日志到Mysql数据库中


下一篇:lambda转化为sql语句(完整版)