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

 

posted @ 2020-09-11 20:33  java小新人  阅读(2483)  评论(0编辑  收藏  举报