leftso 327 0 2019-04-11 22:09:01

文章位置:左搜> 编程技术> 正文

一、环境

spring boot 2.x + mybaties +mysql

二、问题描述

java.sql.SQLException: 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.


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.

错误原因:
出错的原因是mysql的时区值设置的不正确

三、解决办法


解决办法有两种

3.1 解决办法一

修改数据连接url

spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8

修改为:

spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8

3.2 解决办法二

查看mysql的时区配置
show variables like'%time_zone';
mysql时区

mysql默认的时区值是美国,中国的时区要比美国晚8小时,需要采用+8:00的格式
我们登录mysql,查看当前的时区值,发现时区值是system

修改mysql的配置文件
搜索[mysqld],在[mysql]节点下加上这一行
default-time-zone='+08:00'

重启mysql服务