could not create connection to database server.] with root cause
生活随笔
收集整理的這篇文章主要介紹了
could not create connection to database server.] with root cause
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
場景
SpringBoot項目運行后提示:
詳細(xì)提示如下:
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.] with root causejava.lang.NullPointerException: nullat com.mysql.jdbc.ConnectionImpl.getServerCharacterEncoding(ConnectionImpl.java:3286) ~[mysql-connector-java-5.1.27.jar:na]at com.mysql.jdbc.MysqlIO.sendConnectionAttributes(MysqlIO.java:1987) ~[mysql-connector-java-5.1.27.jar:na]at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1913) ~[mysql-connector-java-5.1.27.jar:na]at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1290) ~[mysql-connector-java-5.1.27.jar:na]at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2493) ~[mysql-connector-java-5.1.27.jar:na]at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2526) ~[mysql-connector-java-5.1.27.jar:na]at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2311) ~[mysql-connector-java-5.1.27.jar:na]at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834) ~[mysql-connector-java-5.1.27.jar:na]at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) ~[mysql-connector-java-5.1.27.jar:na]at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_181]at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.8.0_181]at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.8.0_181]at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[na:1.8.0_181]at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) ~[mysql-connector-java-5.1.27.jar:na]at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416) ~[mysql-connector-java-5.1.27.jar:na]at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:347) ~[mysql-connector-java-5.1.27.jar:na]at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136) ~[HikariCP-3.2.0.jar:na]at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369) ~[HikariCP-3.2.0.jar:na]at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198) ~[HikariCP-3.2.0.jar:na]at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467) ~[HikariCP-3.2.0.jar:na]at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541) ~[HikariCP-3.2.0.jar:na]at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-3.2.0.jar:na]at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-3.2.0.jar:na]解決
自己項目的mysql驅(qū)動的版本與本機安裝的mysql的版本不對應(yīng)導(dǎo)致,項目所用驅(qū)動版本過低。
打開cmd,輸入mysql,可以查看本機安裝的mysql的版本為8.0。
所以找到項目中的pom.xml
將mysql驅(qū)動版本修改為:
dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.11</version></dependency>?
注意:
8.0.11版本的mysql驅(qū)動包的driverClass有所變化
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver總結(jié)
以上是生活随笔為你收集整理的could not create connection to database server.] with root cause的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Unknown initial char
- 下一篇: Mysql8.0注意url变更写法