java.sql.SQLException The server time zone value 'xxx' is unrecognized or represe

发布时间: 2020-12-20 19:18:00 作者: 大象笔记

在 Windows 10 上的一个 Spring Boot 项目,连接本地 MySQL 8 数据库。

在 IDEA 中编译,报错:

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 specific time zone value if you want to utilize time zone support.at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql-connector-java-8.0.22.jar:8.0.22]

解决方法

在 application.properties 配置中,添加 serverTimezone 设置:

spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/my_db?serverTimezone=GMT%2B8

这里指定了时区为东八区,其中的 + 需要转义。

我是一名山东烟台的开发者,联系作者