Mybatis serverTimezone时区出现问题
错误信息
我们可以定位错误信息The server time zone value 'Öйú±ê׼ʱ¼ä' is,
则说明了是serverTimezone时区的问题
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: 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.
### The error may exist in com/chun/dao/UserMapper.xml
### The error may involve com.chun.dao.UserMapper.getUserList
### The error occurred while executing a query
### Cause: java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time
出现原因
因为MySQL版本号是8.0以上,需要设置serverTimezone,useSSL等参数
解决
在mybatis-config.xml文件中的property name="url"在后面添加
&serverTimezone=Asia/Shanghai" //注意Shanghai是开头大写
或者
&serverTimezone=GMT%2B8
<property name="url" value="jdbc:mysql://localhost:3306/mybatis?useSSL=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai"/>
Mybatis 插件碰到的时区问题及用法
连接数据库mysql -hlocalhost -uroot -p,回车,输入密码,回车,
show variables like'%time_zone'; (注意不要漏掉后面的分号),回车
设置时区 set time_zone = '+8:00';
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。