The server time zone value ‘xx‘ is unrecognized or represents more than one time zone(SpringBoot错误)

阅读: 评论:0

The server time zone value ‘xx‘ is unrecognized or represents more than one time zone(SpringBoot错误)

The server time zone value ‘xx‘ is unrecognized or represents more than one time zone(SpringBoot错误)

错误描述

SpringBoot连接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 specific time zone value if you want to utilize time zone support.

错误原因

时区问题,服务器的时区的识别或代表多个时区。如果您想利用时区支持,您必须配置服务器或JDBC驱动程序(通过serverTimezone配置属性)使用一个更具体的时区值如果你想利用时区支持。

解决办法

在配置文件的时候添加时区信息就可以解决问题了。
在连接数据库的url后面添加

serverTimezone=GMT%2B8	# 添加时区,GMT%2B8是东八区(也就是北京时间)serverTimezone=UTC	# UTC,简称世界统一时间,跟北京时间相比,比北京早8个小时

【注意**】建议使用serverTimezone=GMT%2B8设置为东八区,如果使用serverTimezone=UTC,那么在编译器上执行的SQL语句,会先以UTC时区进行存储,发送到MySQL数据库,然后MySQL以本地时区进行转换,最终导致执行时间比从编译器上的执行时间早8个小时,也就是造成同一条SQL语句,在MySQL上执行,与编译器执行,结果相差8个小时。
如果没有自定义设置时区,MySQL数据库默认使用的时区是系统时区CST,这个CST又有好多种解释,分别为如下。而MySQL服务器又把CST理解成了美国中部时区(),结果就使用了美国中部时间的时区,而不是后端系统服务器的时区。

spring:datasource: # hikaridriver-class-name: sql.cj.jdbc.Driver # mysql 8username: rootpassword: rooturl: jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8  # serverTimezone=GMT%2B8表示东8区,不然报错time zone

本文发布于:2024-02-02 23:57:45,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170688946347316.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:错误   zone   time   server   xx
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23