SpringBoot链接MySQL数据库时候报时区错误的解决办法

新建Springboot项目链接Mysql数据库时候常常会遇到以下错误:java

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

从上面一段话,咱们能够看出是因为数据库服务器时区没法识别或者超过一个时区致使,因此咱们只须要给指定一个时区便可解决,有两种解决办法。sql

一、数据库设置时区

//查看数据库时区信息
show variables like '%time_zone%'
//设置时区为东八区时区
set global time_zone = '+8:00'

 root用户登陆数据库执行sql语句便可(在数据库链接工具中查询执行也可)。数据库

二、项目中配置文件中数据库链接url中加&serverTimezone=GMT%2B8

只须要加上以下图配置便可:服务器

配置奉上: mybatis

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

以上两个办法亲测有效。工具