出現的問題:
1、問題:需要更新驅動的版本號問題
could not create connection to database server 08001
修改pom.xml:
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.11</version> <scope>runtime</scope> </dependency>
MySQL8.0版本需要更換驅動為“com.mysql.cj.jdbc.Driver”,之前的“com.mysql.jdbc.Driver”已經不能在MySQL 8.0版本使用了,官方文檔鏈接:https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-api-changes.html;
描述如下:The name of the class that implements java.sql.Driver in MySQL Connector/J has changed from com.mysql.jdbc.Driver to com.mysql.cj.jdbc.Driver. The old class name has been deprecated.
另外mysql-connector-java也推薦更新到8.0的版本(https://dev.mysql.com/downloads/connector/j/)。
2、問題:使用了 Mysql 最新版驅動
The server time zone value '?й???????' is unrecognized or represents more than one time zone
解決方案:
1、一種是降版本,並不推薦,如果需要降版本5.5版本可以滿足基本需要;
2、還有一種是在jdbc連接的url后面加上serverTimezone=UTC或GMT即可,如果需要指定使用gmt+8時區,需要寫成GMT%2B8,不然可能會報錯誤,解析為空
jdbc.url=jdbc:mysql://localhost:3306/項目名稱?serverTimezone=UTC&characterEncoding=utf-8