The server time zone value xxx is unrecognized or represents more than one time zone

位置:首页>文章>详情   分类: 教程分享 > Java教程   阅读(804)   2023-03-28 11:29:14

一、环境

spring boot 2.x + mybaties +mysql

二、问题描述

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.


Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: 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的时区值设置的不正确

三、解决办法


解决办法有两种

3.1 解决办法一

修改数据连接url

spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8

修改为:

spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8

3.2 解决办法二

查看mysql的时区配置
show variables like'%time_zone';
mysql时区

mysql默认的时区值是美国,中国的时区要比美国晚8小时,需要采用+8:00的格式
我们登录mysql,查看当前的时区值,发现时区值是system

修改mysql的配置文件
搜索[mysqld],在[mysql]节点下加上这一行
default-time-zone='+08:00'

重启mysql服务


 
地址:https://www.leftso.com/article/561.html

相关阅读

Spring Boot 2.0 Redis整合,通过spring boot 2.0整合Redis作为spring缓存框架的实现。
spring boot 2.0 security 5.0 整合,实现自定义表单登录。spring boot 2.0框架使用。
Spring Boot 2.0,Spring框架的Spring Boot 中的Spring Boot Actuator变化讲解。并且了解如何在Spring Boot 2.0中使用Actuator...
Spring Boot 1.x升级到Spring Boot 2.0迁移指南
Spring Boot 2.0 有哪些新特性_Spring Boot 2.0新功能,在本文中,我们将探讨为Spring Boot 2.0计划的一些更改和功能。我们还会描述这些变化如何帮助我们提高...
Spring Boot 2.0 绑定properties属性资源文件 Spring Boot 2.0 读取properties配置文件值 Spring Boot 2.0获取properties配...
Spring Boot 2.0 支持的Apache Camel 版本发布了_Apache Camel 2.22发布支持Spring Boot 2.0
本文将介绍Spring Boot和HikariCP示例。HikariCP是快速,简单,可靠和生产就绪的JDBC连接池。在Spring Boot 2.0版本中,默认数据库池技术已从Tomcat P...
Spring Boot 2.0 @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") 注解格式化日期失效原因及解决。