mysql 8.0 Druid连接时调用getServerCharset报空指针异常解决方法

Posted 太白的技术博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql 8.0 Druid连接时调用getServerCharset报空指针异常解决方法相关的知识,希望对你有一定的参考价值。

类似错误信息如下:

16:52:01.163 [Druid-ConnectionPool-Create-1641320886] ERROR com.alibaba.druid.pool.DruidDataSource - create connection error, url: jdbc:mysql://localhost:3306/jf?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

at sun.reflect.GeneratedConstructorAccessor26.newInstance(Unknown Source) ~[?:?]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_144]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_144]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408) ~[mysql-connector-java-5.1.32.jar:?]
at com.mysql.jdbc.Util.getInstance(Util.java:383) ~[mysql-connector-java-5.1.32.jar:?]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1023) ~[mysql-connector-java-5.1.32.jar:?]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:997) ~[mysql-connector-java-5.1.32.jar:?]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:983) ~[mysql-connector-java-5.1.32.jar:?]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:928) ~[mysql-connector-java-5.1.32.jar:?]
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2576) ~[mysql-connector-java-5.1.32.jar:?]
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2309) ~[mysql-connector-java-5.1.32.jar:?]
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834) ~[mysql-connector-java-5.1.32.jar:?]
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46) ~[mysql-connector-java-5.1.32.jar:?]
at sun.reflect.GeneratedConstructorAccessor23.newInstance(Unknown Source) ~[?:?]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_144]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_144]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408) ~[mysql-connector-java-5.1.32.jar:?]
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:419) ~[mysql-connector-java-5.1.32.jar:?]
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344) ~[mysql-connector-java-5.1.32.jar:?]
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1375) ~[druid-1.0.11.jar:1.0.11]
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1431) ~[druid-1.0.11.jar:1.0.11]
at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:1857) [druid-1.0.11.jar:1.0.11]

Caused by: java.lang.NullPointerException

at com.mysql.jdbc.ConnectionImpl.getServerCharset(ConnectionImpl.java:3299) ~[mysql-connector-java-5.1.32.jar:?]
at com.mysql.jdbc.MysqlIO.sendConnectionAttributes(MysqlIO.java:1967) ~[mysql-connector-java-5.1.32.jar:?]
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1893) ~[mysql-connector-java-5.1.32.jar:?]
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1287) ~[mysql-connector-java-5.1.32.jar:?]
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2494) ~[mysql-connector-java-5.1.32.jar:?]
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2527) ~[mysql-connector-java-5.1.32.jar:?]
... 12 more


以上是关于mysql 8.0 Druid连接时调用getServerCharset报空指针异常解决方法的主要内容,如果未能解决你的问题,请参考以下文章

破案了,同事升级了MySQL驱动8.0,导致应用大量超时

Druid 连接池,重启Mysql数据库后,Druid会自动重新连接不,该在哪配置?

别再乱升级 MySQL 驱动了。。

用 MHA 做 MySQL 读写分离,频繁爆发线上生产事故后,泪奔分享 Druid 连接池参数优化实战

数据库连接中断-连接池druid

Druid(德鲁伊)连接数据库