Sping-boot项目报错:The server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one ti

Sping-boot项目报错: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.

查阅到了许多方法,整理一下:

NO.1(未解决我的问题)

解决:

在jdbc连接的url后面加上serverTimezone=GMT即可解决问题**

(在你的yml配置文件中)Sping-boot项目报错:The server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one ti

若你的程序中有配置代码,修改如下:

serverTimezone=GMT添加到配置代码中即可
Sping-boot项目报错:The server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one ti

原理:使用的数据库是MySQL,驱动是8.0.18,这是由于数据库和系统时区差异所造成的,在jdbc连接的url后面加上serverTimezone=GMT即可解决问题,如果需要使用gmt+8时区,需要写成GMT%2B8,否则会被解析为空。再一个解决办法就是使用低版本的MySQL jdbc驱动,5.1.28不会存在时区的问题。


NO.2(未解决我的问题)

解决

在yml中配置url的时候不能简单写成 :
jdbc:mysql://localhost:3306/yzu

而是要写成 :
jdbc:mysql://localhost:3306/yzu?serverTimezone=UTC

**若像我一样,在程序中配置的url,修改如下:
**
Sping-boot项目报错:The server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one ti

原因

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


NO.3(成功解决)

serverTimezone=Asia/Shanghai添加到配置代码中即可

Sping-boot项目报错:The server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one ti

显示成功

Sping-boot项目报错:The server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one ti