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 信息