您当前的位置: 首页 >  sql

一一哥Sun

暂无认证

  • 3浏览

    0关注

    622博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value异常解决方案

一一哥Sun 发布时间:2019-09-06 16:14:58 ,浏览量:3

一.异常信息

在连接数据库时,突然出现了异常异常信息: 

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的无效连接属性异常:服务器时区值无法辨认或表示多个时区,如果你想使用时区支持,你必须通过服务器时区配置属性来配置服务器或JDBC驱动从而使用更具体的时区值。

二.异常原因

这是因为 mysql升级到8.0及以上,添加了许多新特性,安全性也得到提升。当然操作时也增加了些繁琐,需要考虑到的时区问题便是其中之一。

三.解决办法 1.通过配置JDBC驱动的连接字符串:

即配置url参数中的serverTimezone属性来解决异常,需要在连接字符串 url 后加上 serverTimezone=UTC.

2.服务器默认时区跟随系统时区。通过服务器时区配置属性来配置服务器的时区。 2.1 查看当前mysql系统时间
select now();

2.2 查看当前mysql区时
show variables like "%time_zone%";

2.3 修改mysql时区
//修改mysql全局时区为东八区,即表示北京时间

set global time_zone = '+8:00';

flush privileges;

//时区修改生效之后,再次查询mysql时区

show variables like "%time_zone%";

 

关注
打赏
1665624836
查看更多评论
立即登录/注册

微信扫码登录

0.0579s