zl程序教程

您现在的位置是:首页 >  后端

当前栏目

超详解The server time zone value ‘�й���׼ʱ��‘ is unrecognized or represents more than one time zone

server 详解 The is or value Time One
2023-09-27 14:28:48 时间

1.问题分析

image-20220724010647119

2.解决方案

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

image-20220724010729311

3.使用低版本Mysql驱动警告分析

在将版本修改为5.1.49(或者其他的低版本Mysql驱动)后,会出现警告:

image-20220724011848898

Establishing SSL connection without server’s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn’t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false’. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

不建议在没有服务器身份验证的情况下建立SSL连接。根据MySQL 5.5.45+、5.6.26+和5.7.6+的要求,如果未设置显式选项,则默认情况下必须建立SSL连接。为了符合不使用SSL的现有应用程序,verifyServerCertificate属性设置为“false”。您需要通过设置useSSL=false显式禁用SSL,或者设置useSSL=true并为服务器证书验证提供信任库。

对此,我们可以在配置spring.datasource.url时,可以在url后面加上 useSSL=false

3.总结

使用不同的数据库驱动版本可能会导致数据库和系统时区差异,或者低版本的警告。
动版本可能会导致数据库和系统时区差异,或者低版本的警告。
在使用数据库驱动版本时要充分考虑,结合需求去使用。