Java出现The server time zone value '�й���׼ʱ��' is unrecogni的解决

报错

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.

原因:

原因是因为使用了Mysql Connector/J 6.x以上的版本,然后就报了时区的错误

遇到的问题 servertime=UTC导致时间差8个小时(MySQL jdbc 6.0 版本以上必须配置此参数)

解决办法
在配置url的时候不能简单写成 :

jdbc:mysql://localhost:3306/数据库名

而是要写成 :

jdbc:mysql://localhost:3306/数据库名?serverTimezone=UTC

而UTC代表的是全球标准时间 ,但是我们使用的时间是北京时区也就是东八区,领先UTC八个小时。

UTC + (+0800) = 本地(北京)时间
解决方案

url的时区使用中国标准时间。也是就

jdbc:mysql://localhost:3306/数据库名?serverTimezone=Asia/Shanghai