本文介绍了连接Java-MySql:不允许公钥检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用连接器8.0.11使用Java来连接MySql数据库。一切似乎都没问题,但我有这个例外:
I try to conncect MySql database with Java using connector 8.0.11. Everything seems to be ok but i have this exception:
线程main中的异常java.sql.SQLNonTransientConnectionException:不允许公钥检索
Exception in thread "main" java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
这是我第一次使用MySql而我找不到任何解决方案。感谢您的帮助!
It is my first time with MySql and I couln't find any solutions. Thanks for your help!
堆栈跟踪:
Exception in thread "main" java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:108) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at
com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:862) at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:444) at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:230) at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:226) at com.mysql.cj.jdbc.MysqlDataSource.getConnection(MysqlDataSource.java:438) at com.mysql.cj.jdbc.MysqlDataSource.getConnection(MysqlDataSource.java:146) at com.mysql.cj.jdbc.MysqlDataSource.getConnection(MysqlDataSource.java:119) at ConnectionManager.getConnection(ConnectionManager.java:28) at Main.main(Main.java:8)
连接器管理器:
public class ConnectionManager {
public static final String serverTimeZone = "UTC";
public static final String serverName = "localhost";
public static final String databaseName ="biblioteka";
public static final int portNumber = 3306;
public static final String user = "anyroot";
public static final String password = "anyroot";
public static Connection getConnection() throws SQLException {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setUseSSL( false );
dataSource.setServerTimezone( serverTimeZone );
dataSource.setServerName( serverName );
dataSource.setDatabaseName( databaseName );
dataSource.setPortNumber( portNumber );
dataSource.setUser( user );
dataSource.setPassword( password );
return dataSource.getConnection();
}
}
推荐答案
你应该为mysql-connector添加客户端选项 allowPublicKeyRetrieval = true
You should add client option to your mysql-connector allowPublicKeyRetrieval=true
还可以帮助添加 useSSL = false
这篇关于连接Java-MySql:不允许公钥检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!