mysql5和mysql8配置的小差異

springboot2.1以上配置的mysql的版本是8.x,和以前用的mysql5在配置上有點小區別,記錄一下

mysql5:

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mybatis_plus
spring.datasource.username=root
spring.datasource.password=123456

 

mysql8:

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mybatis_plus?serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=123456

 

注意:

1、這裏的 mysql8使用了 ?serverTimezone=GMT%2B8 後綴,因爲Spring Boot 2.1 集成了 8.0版本的jdbc驅動,這個版本的 jdbc 驅動需要添加這個後綴,否則運行測試用例報告如下錯誤:

java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more 

2、兩者驅動的區別  ,在 jdbc 8 中 建議使用的驅動有cj,之前的 com.mysql.jdbc.Driver 已經被廢棄,否則運行測試用例的時候會有 WARN 信息

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章