前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >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
1.5K0
发布2019-06-28 14:45:39
举报
文章被收录于专栏:凯哥Java凯哥Java

在使用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)

010a96dd3b5d349d79ff230889d91b34.png
010a96dd3b5d349d79ff230889d91b34.png

查看错误的数据库链接:

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

512a9e792965b233a734a997eb86b5a3.png
512a9e792965b233a734a997eb86b5a3.png

错误原因分析:

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

解决方案一:

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

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

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

解决方案二:

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

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

show variables like '%time_zone%';

69bc85f3d31be7f990f051c87172e80e.png
69bc85f3d31be7f990f051c87172e80e.png

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

set global time_zone='+8:00';

修改后:

de67b3de7565491e6a14db24a7b23eff.png
de67b3de7565491e6a14db24a7b23eff.png

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

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

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

下面看看凯哥的:

代码语言:javascript
复制
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 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档