在新电脑上安装了MySQL8.0,打开原来的一个项目去连接时,报如下错误
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
Caused by: java.lang.NullPointerException
at com.mysql.jdbc.ConnectionImpl.getServerCharset(ConnectionImpl.java:3005)
at com.mysql.jdbc.MysqlIO.sendConnectionAttributes(MysqlIO.java:1916)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1845)
经排查,是因为JDBC驱动版本问题导致的,项目原来使用的MySQL版本是5.X,现在使用MySQL8.0,驱动需要相应的跟新,如下:
mysql
mysql-connector-java
8.0.11
另外,application.properties文件中的数据库配置项也需要相应变化:
spring.datasource.url=jdbc:mysql://localhost:3306/toutiao?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8
spring.datasource.username=root