高版本SpringBoot连接mysql数据库时区异常报错:The server time zone value is unrecognized or represents more than...

分类:计算机 | Spring | SpringBoot | 异常问题 1137
更新:2021-02-23 21:24:11
编辑

1 异常描述

将SpringBoot的版本从2.1.17.RELEASE升级到2.2.10.RELEASE以后,连接mysql数据库时报错“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”

2 异常解决

原来的mysql连接字符串是:

jdbc:mysql://127.0.0.1:3306/db1?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true

在连接字符串后面加上&serverTimezone=GMT%2B8即可,如下所示:

jdbc:mysql://127.0.0.1:3306/db1?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&serverTimezone=GMT%2B8