首页 > 技术文章 > com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. 问题解决方法

wutianqi 2019-03-19 21:00 原文

一、问题

今天用mybatis连接数据库时出现了如下错误:

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.

查看异常可以大概知道是因为服务器的时区(timezone)无法识别或者不止一个导致的,让我们配置数据库或JDBC的时区。

二、解决办法

1.配置jdbc驱动时区,在jdbc连接mysql的url中加上时区:spring.datasource.url=jdbc:mysql://localhost:3306/forum-dev?serverTimezone=GMT%2B8,这种方法比较推荐,一劳永逸。

2.配置数据库:这种方法据网上说,如果重启电脑,那么还是会失效,所以采用第一种即可。

推荐阅读