阅读:41
2022-03-18 17:46:43.428 ERROR 20704 — [eate-1849941462] com.alibaba.druid.pool.DruidDataSource : create connection SQLException, url: jdbc:mysql:///ymcc-uaa?&useSSL=false&serverTimezone=UTC, errorCode 0, state 08001
java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110) ~[mysql-connector-java-8.0.19.jar:8.0.19]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.19.jar:8.0.19]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.19.jar:8.0.19]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) ~[mysql-connector-java-8.0.19.jar:8.0.19]
at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:456) ~[mysql-connector-java-8.0.19.jar:8.0.19]
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) ~[mysql-connector-java-8.0.19.jar:8.0.19]
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197) ~[mysql-connector-java-8.0.19.jar:8.0.19]
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1513) ~[druid-1.1.9.jar:1.1.9]
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1578) ~[druid-1.1.9.jar:1.1.9]
at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2466) ~[druid-1.1.9.jar:1.1.9]
mysql8.x版本的数据库在连接的时候报错java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
只要在url的后边加上allowPublicKeyRetrieval=true重启即可
allowPublicKeyRetrieval=true
jdbc:mysql:///ymcc-system?&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
1.useSSL=falseMySQL 8.0 以上版本不需要建立 SSL 连接的,需要显示关闭
2.allowPublicKeyRetrieval=true 允许客户端从服务器获取公钥。
3.serverTimezone=UTC 设置时区,mysql驱动8.0+也要指定时区,不然也会报一些错
最后总结:如果您使用的mysql是8.0+,建议最好把以上三个参数设置下,避免发生一些莫名错误。