一、错误描述
mybatis连接mysql时出现如下错误
The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone
二、错误原因
mysql时区问题
三、解决办法
1、第一种解决办法是将mysql安装根目录下的my-default.ini文件重命名为my.ini,然后在[mysqld]下加入default-time-zone = '+8:00'
[mysqld]
default-time-zone = '+8:00'
注意:这种方法是永久性的,mysql或者电脑重启依然起作用
2、第二种方法是通过命令或sql语句修改
--查看mysql时区
show variables like '%time_zone%';
--查看当前时间
select now();
--设置为时区为东八区
set global time_zone = '+8:00';
注意:这种方法是临时性的,如果mysql或者电脑重启需要重新修改
3、第三种方法是修改连接字符串,在后面添加serverTimezone=GMT%2B8
jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
注意:这种方法只对当前项目有用