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

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值