解决java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or

SpringBoot在连接数据库的时候会出现如下报错,原因是时间区域时差问题

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.

这时候需要在配置数据库的url后面加上

serverTimezone=GMT%2B8 

UTC代表的是全球标准时间 ,但是我们使用的时间是北京时区也就是东八区,领先UTC八个小时。

datasource:
  driver-class-name: com.mysql.cj.jdbc.Driver
  url: jdbc:mysql://localhost:3306/mytest?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2B8
  username: root
  password: 123456

 

你可能感兴趣的:(Mysql)