JDBC:The server time zone value ‘�й���ʱ��‘ is unrecognized or represents more than one time zone.
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或者其他问题导致有时间差,除非你很明确知道具体的用法以及可能造成的时间差。
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.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_222]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_222]
at sun.reflect.DelegatingConstructorAccessorImpl.__newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_222]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45009) ~[?:1.8.0_222]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45012) ~[?:1.8.0_222]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_222]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:132) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2243) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2267) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1319) ~[mysql-connector-java-8.0.16.jar:8.0.16]
at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:868) ~[mysql-connector-java-8.0.16.jar:8.0.16]
... 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
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
还没有评论,来说两句吧...