一、问题描述
通过java连接mysql数据库字符串配置提示“ java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed ”报错异常提示。
java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed@b@@b@ at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.jav@b@a:110)@b@ at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.jav@b@a:97)@b@ at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(@b@SQLExceptionsMapping.java:122)@b@ at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)@b@@b@ at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)@b@ at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)@b@@b@ at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.j@b@ava:207)@b@ at java.sql.DriverManager.getConnection(DriverManager.java:664)@b@ at java.sql.DriverManager.getConnection(DriverManager.java:247)@b@ at com.xwood.engine.common.util.MySQLDBUtil.getConnection(MySQLDBUtil.ja@b@va:36)@b@ at com.xwood.engine.common.util.MySQLDBUtilExt.<clinit>(MySQLDBUtilExt.j@b@ava:19)@b@ at com.xwood.engine.index.solrj.SQLUnitDao.getProcesserS0Data(SQLUnitDao@b@.java:35)@b@ at com.xwood.engine.index.solrj.SolrCoreProcesser.load(SolrCoreProcesser@b@.java:44)@b@ at com.xwood.engine.index.solrj.SolrCoreProcesser.processStep(SolrCorePr@b@ocesser.java:35)@b@ at com.xwood.engine.BaseCommonProcesser$1.run(BaseCommonProcesser.java:3@b@4)@b@ at java.util.TimerThread.mainLoop(Timer.java:555)@b@ at java.util.TimerThread.run(Timer.java:505)@b@Exception in thread "Timer-0" java.lang.ExceptionInInitializerError@b@ at com.xwood.engine.index.solrj.SQLUnitDao.getProcesserS0Data(SQLUnitDao@b@.java:35)@b@ at com.xwood.engine.index.solrj.SolrCoreProcesser.load(SolrCoreProcesser@b@.java:44)@b@ at com.xwood.engine.index.solrj.SolrCoreProcesser.processStep(SolrCorePr@b@ocesser.java:35)@b@ at com.xwood.engine.BaseCommonProcesser$1.run(BaseCommonProcesser.java:3@b@4)@b@ at java.util.TimerThread.mainLoop(Timer.java:555)@b@ at java.util.TimerThread.run(Timer.java:505)@b@Caused by: java.lang.RuntimeException: Public Key Retrieval is not allowed@b@ at com.xwood.engine.common.util.MySQLDBUtil.getConnection(MySQLDBUtil.ja@b@va:40)@b@ at com.xwood.engine.common.util.MySQLDBUtilExt.<clinit>(MySQLDBUtilExt.j@b@ava:19)@b@ ... 6 more
二、解决方法
1)在mysql的连接串上添加"&allowPublicKeyRetrieval=true",原来连接串如下
mysql.jdbc.1.url=jdbc:mysql://192.168.1.5:3306/xwood_index?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull@b@@b@&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8
修改后如下
mysql.jdbc.1.url=jdbc:mysql://192.168.1.5:3306/xwood_index?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull@b@&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true