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的时区值设置的不正确。
解决办法有两种
修改数据连接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
查看mysql的时区配置
show variables like'%time_zone';
mysql默认的时区值是美国,中国的时区要比美国晚8小时,需要采用+8:00的格式。
我们登录mysql,查看当前的时区值,发现时区值是system
修改mysql的配置文件
搜索[mysqld],在[mysql]节点下加上这一行
default-time-zone='+08:00'
重启mysql服务
http://blog.xqlee.com/article/561.html