JDBC:The server time zone value ‘�й���׼ʱ��‘ is unrecognized or represents more than one time zone.

雨点打透心脏的1/2处 2024-04-18 15:26 88阅读 0赞

2020年10月9日更新:使用Asia/Shanghai来替代具有不确定性的UTC/GMT(很多人会以为可以UTC+8或者GMT+8,想法很美好但那种用法是不存在的)。新增DBeaver / IDEA 设置jdbc属性方法。

背景

今天项目切换到了mysql8.0.12,结果还多了一个报错,看来8和5.7的差别还真大。。。烦烦烦。。。

补充,请注意…即使没有升级mysql到8.x,只升级jdbc到8.x也会导致该问题。

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.

就是说mysql的服务器时区无法识别或存在/代表多个时区。您必须在JDBC的URL指定serverTimezone=Asia/Shanghai来解决这个问题,请勿使用 serverTimezone=UTC 或者serverTimezone=GMT 否则会因为linux和windows或者其他问题导致有时间差,除非你很明确知道具体的用法以及可能造成的时间差。

  1. 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. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_222]
  3. at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_222]
  4. at sun.reflect.DelegatingConstructorAccessorImpl.__newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_222]
  5. at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45009) ~[?:1.8.0_222]
  6. at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45012) ~[?:1.8.0_222]
  7. at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_222]
  8. at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.16.jar:8.0.16]
  9. at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85) ~[mysql-connector-java-8.0.16.jar:8.0.16]
  10. at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:132) ~[mysql-connector-java-8.0.16.jar:8.0.16]
  11. at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2243) ~[mysql-connector-java-8.0.16.jar:8.0.16]
  12. at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2267) ~[mysql-connector-java-8.0.16.jar:8.0.16]
  13. at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1319) ~[mysql-connector-java-8.0.16.jar:8.0.16]
  14. at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:868) ~[mysql-connector-java-8.0.16.jar:8.0.16]
  15. ... 10 more

同时也使用与以下情况:

  • No timezone mapping entry for ‘Shanghai‘
  • com.mysql.cj.exceptions.WrongArgumentException: No timezone mapping entry for ‘UTC+8’.

Solution

于是我的jdbc url就变得无比的长。。。解决以上问题需要加多一个&serverTimezone=UTC

  1. url: jdbc:mysql://localhost:3306/mcms?autoReconnect=true&useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&serverTimezone=UTC

DBEAVER/IDEA设置

无论是什么工具或者IDE,中心思想都是增加一个serverTimezone的驱动属性,value= Asia/Shanghai
在这里插入图片描述

serverTimezone = Asia/Shanghai

在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,88人围观)

还没有评论,来说两句吧...

相关阅读