报错:
Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: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.
解决方法:
在URL里添加serverTimezone=UTC即可解决
url: jdbc:mysql://localhost/db?serverTimezone=UTC
展开介绍:
先说一下com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver的区别
com.mysql.jdbc.Driver 是 mysql-connector-java 5中的,
com.mysql.cj.jdbc.Driver 是 mysql-connector-java 6中的
JDBC连接Mysql6 com.mysql.cj.jdbc.Driver, 需要指定时区serverTimezone,否则就会报错
在设定时区的时候,如果设定serverTimezone=UTC,会比中国时间早8个小时,如果在中国,可以选择Asia/Shanghai或者Asia/Hongkong,例如:
url: jdbc:mysql://localhost/db?serverTimezone=Asia/Shanghai
可用的时区都在/usr/share/zoneinfo目录下