解决MySQL报错The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents .....

1.前言 

用SpringBoot+MyBatis+MySQL搭建项目开发环境的时候启动项目发现报了一个很奇怪的错,报错内容如下:

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报错The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents ....._第1张图片

后来查阅资料发现这都是因为安装mysql的时候时区设置的不正确 mysql默认的是美国的时区,而我们中国大陆要比他们迟8小时,采用+8:00格式。

解决方法1:

SHOW VARIABLES LIKE '%time_zone%';

解决MySQL报错The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents ....._第2张图片

SET GLOBAL time_zone='+8:00';

然后重启mysql。

方法2:

在jdbc连接的url后面加上serverTimezone=GMT即可解决问题,如果需要使用gmt+8时区,需要写成GMT%2B8,否则会被解析为空。再一个解决办法就是使用低版本的MySQL jdbc驱动,5.1.28不会存在时区的问题。

方法3:

1.修改MySQL的配置文件,MySQL配置文件是my.ini文件在你的安装目录下去找,我的是在C:\Program Files (x86)\MySQL\MySQL Server 5.5\my.ini

找到这个文件之后用Notepad++打开它,搜索[mysqld]节点在节点下面加上下面这句话

default-time-zone='+08:00'
重启MySQL的服务,执行show variables like '%time_zone%';这句命令

解决MySQL报错The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents ....._第3张图片

 修改成功。

你可能感兴趣的:(解决MySQL报错The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents .....)