Mysql連接驅動8.0版本改動


mysql-connector-java.jar升級到8版本以后,驅動和連接地址的書寫發生了一些改動,不然項目啟動會進行報錯

1、驅動類發生改變

由 com.mysql.jdbc.Driver 改為 com.mysql.cj.jdbc.Driver

以前的com.mysql.jdbc.Driver也還能用,不過會提交你使用新的驅動類,提示如下:

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is 
automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

 

 

2、數據庫連接地址發生改動

spring.datasource.url=jdbc:mysql://localhost:3306/glxy

數據庫連接地址上必須要指定時區(serverTimezone=GMT%2B8),不然會報如下錯誤:

java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. 
You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specifc time zone value if you want to utilize time zone support.

另外,在數據庫連接地址上要需要額外指定字符編碼(characterEncoding=utf8),如果不指定 like查詢可能不會生效,明明有數據卻無法查出

 

完整地址寫法如下:

spring.datasource.url=jdbc:mysql://localhost:3306/glxy?serverTimezone=GMT%2B8&characterEncoding=utf8&useSSL=false&useUnicode=true

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM