首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >spring boot连接mysql提示The server time zone value xxx错误

spring boot连接mysql提示The server time zone value xxx错误

作者头像
凯哥Java
发布2019-06-28 14:45:39
发布2019-06-28 14:45:39
1.8K00
代码可运行
举报
文章被收录于专栏:凯哥Java凯哥Java
运行总次数:0
代码可运行

在使用spring boot +Mysql组合的时候。遇到了连接数据库错误。信息:The server time zone value xxx

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.

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

查看错误的数据库链接:

jdbc:mysql://127.0.0.1:3306/springbootautocode?user=root&password=123456

错误原因分析:

这是因为mysql 服务器时区问题导致的。

解决方案一:

直接在url后面添加:&serverTimezone=UTC

如果想或者添加:serverTimezone=GMT%2B8

因为中国的时区是在东八区。所以这里设置时区

解决方案二:

修改mysql 服务器的时区配置。

查看当前mysql服务器时区语句:

show variables like '%time_zone%';

修改time_zone的值为+8:00语句:

set global time_zone='+8:00';

修改后:

这里不推荐第二种修改方式。

因为如果修改了服务器时区的话,原来老数据的时间就不比时间少8个小时。这个时候会导致很多未知的问题出现。

所以强烈推荐第一种修改方式。方便又简单。

下面看看凯哥的:

代码语言:javascript
代码运行次数:0
运行
复制
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/springbootautocode?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8

修改完成后,重启服务,就可以正常访问了。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-06-14 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档