---
title: "The server time zone value 'ÖÐ¹ú±ê×¼Ê±¼ä' is unrecognized or represents more ..."
author: "linyinpeng1989"
date: "2018-08-23T13:41:21Z"
tags: []
categories: ["数据库"]
slug: "the-server-time-zone-value-is-unrecognized-or-represents-more"
draft: false
lastmod: "2018-08-23T13:42:17Z"
id: 2429218
url: "https://chaser520.iteye.com/blog/2429218"
---

在程序运行时出现这个错误，为了避免以后再次遇到，在此记录一下。

 

```
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) ~[na:1.8.0_161]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_161]
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_161]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_161]
	at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:59) ~[mysql-connector-java-8.0.11.jar:8.0.11]
	at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:83) ~[mysql-connector-java-8.0.11.jar:8.0.11]
	at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:128) ~[mysql-connector-java-8.0.11.jar:8.0.11]
	at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2201) ~[mysql-connector-java-8.0.11.jar:8.0.11]
	at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2225) ~[mysql-connector-java-8.0.11.jar:8.0.11]
	at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1391) ~[mysql-connector-java-8.0.11.jar:8.0.11]
	at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:895) ~[mysql-connector-java-8.0.11.jar:8.0.11]
	... 77 common frames omitted
```

 

 

主要是因为升级了mysql连接驱动，如下

 

```
compile('mysql:mysql-connector-java:8.0.11')
```

从错误上看应该是时区的错误，所以我们只需要设置完毕系统的时区即可。

 

 

解决办法：在连接url中加入参数 serverTimezone=GMT%2B8，GMT%2B8代表东八区

```
jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&autoReconnect=true&serverTimezone=GMT%2B8
```

 

 

 还有另外一种解决方法：设置整个数据库的时区

```
show variables like '%time_zone%'
set global time_zone='+8:00';
```