在使用SpringBoot 2.1.0 + mysql5.7 + mybatis 时,查询数据库报错:
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.
报错原因:
SpringBoot2.1.0在没有指定MySQL驱动版本的情况下它自动依赖的驱动是8.0的版本,而在安装mysql数据库时一般都不会设置时区,系统默认的时区是美国,北京时间比美国时间晚8个小时。所以出现了The server time zone value ‘Öйú±ê׼ʱ¼ä’ is unrecognized … 的问题。
1、最简单解决办法:
指定mysql-connector-java的版本为5.x.xx , 如下
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.47</version> </dependency>
2、修改MySQL配置文件
修改mysql配置文件;my.ini或者my-default.ini的配置文件。打开配置文件修改如下在[mysqld]下添加 default-time-zone=’+08:00’