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

Moshow鄭鍇發表於2020-04-07

背景

今天專案切換到了mysql8.0.12,結果還多了一個報錯,看來8和5.7的差別還真大。。。煩煩煩。。。

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=UTC來解決這個問題=。=

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

Solution

於是我的jdbc url就變得無比的長。。。解決以上問題需要加多一個&serverTimezone=UTC

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

相關文章