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

更新日期: 2020-12-20 阅读次数: 2312 字数: 121 分类: spring

在 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

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

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式