新建Springboot项目连接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.
从上面一段话,我们可以看出是由于数据库服务器时区无法识别或者超过一个时区导致,所以我们只需要给指定一个时区即可解决,有两种解决办法。
1、数据库设置时区
//查看数据库时区信息
show variables like '%time_zone%'
//设置时区为东八区时区
set global time_zone = '+8:00'
root用户登录数据库执行sql语句即可(在数据库连接工具中查询执行也可)。
2、项目中配置文件中数据库连接url中加&serverTimezone=GMT%2B8
只需要加上如下图配置即可:
配置奉上:
datasource:
url: jdbc:mysql://192.168.1.63:3306/mybatistest?
useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
以上两个办法亲测有效。