[报错解决]The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone.

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Jin_Kwok/article/details/82740276

报错信息:

在使用mysql-connector-java-6.0.6连接mysql数据库的时候,出现了报错:The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone.

报错原因:

顾名思义,服务器的时区值”?й???????无法识别或代表多个时区。您必须配置服务器或驱动程序(通过serverTimezone配置属性)使用一个更具体的时区值如果你想利用时区支持。说白了,没有配置时区,有可能出现问题。

解决方案:

在通过在数据库连接URL后,加上?serverTimezone=UTC 

为什么是UTC

环境需要:如要维护多国环境如中美,时区一致便与维护 

避免风险:避免PDT时区换算出错

实际案例:

1. xxx.properties类型配置文件,如spring配置文件,类似如下配置即可

spring.datasource.url=jdbc:mysql://localhost:3306/chat?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC

2.xxx.xml 类型配置文件,如mybatis的配置文件mybatis.cfg.xml,需要注意:xml文件不能识别分割符“&”,需用“&”替代,否则将报错:org.xml.sax.SAXParseException; lineNumber: 30; columnNumber: 109; 对实体 "serverTimezone" 的引用必须以 ';' 分隔符结尾。配置示例如下:

<property name="url" value="jdbc:mysql://localhost:3306/mysql?useUnicode=true&amp;serverTimezone=UTC" />

猜你喜欢

转载自blog.csdn.net/Jin_Kwok/article/details/82740276