Mysql配置报错:The server time zone value ‘�й���ʱ��’ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver
在学习Spring Cloud的过程中,配置mysql数据库后启动项目报错:
The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver
因为时区问题,所以在配置文件中要配置好时区serverTimezone=UTC
:
spring:
application:
name: product
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: 123456
url: jdbc:mysql://127.0.0.1:3306/springcloud?characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
准确来说归为Spring Boot的报错。
结果在后面的测试中出现了别的问题,使用java的new Date新建的时间插入到mysql中,mysql的时间会不一样。这是时区的问题。
解决方案: 将时区改为CTT(Asia&Shanghai)
url: jdbc:mysql://127.0.0.1:3306/table?characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
github: https://github.com/Hikiy
作者:Hiki
创建日期:2019.06.18
更新日期:2019.06.18
(转载本站文章请注明作者和出处 Hiki)