IDEA连接mysql报错,Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' prope

转载于:
参考1
参考2

翻译过来就是:服务器返回无效时区。进入“高级”选项卡,手动设置“serverTimezone”属性。

看起来是时区出了问题。时区怎么会出问题?坑真多。网上搜了各种解决办法,琳琅满目,复杂的简单的,总算是解决了!

第一种解决方案

原因:
首先,出现该问题的原因是MySQL驱动jar中的默认时区是UTC。

UTC代表的是全球标准时间 ,但是我们使用的时间是北京时区也就是东八区,领先UTC八个小时。

因为时区不一致,所以提示Server returns invalid timezone. Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually
服务器返回了无效的时区,去“高级”标签中手工设置“serverTimezon"属性值。

IDEA连接mysql报错,Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' prope

第二种解决方案

解决方案
我的问题出在两块,第一,设置mysql的时区。第二,mysql驱动的版本。详细步骤如下:

第一,设置mysql时区。
1,我们先来检查下mysql时区。

( 这里有个小插曲~~~~~~~你的mysql,配置好环境变量了吗 )
IDEA连接mysql报错,Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' prope

配置完环境变量,就可以在命令窗口直接执行下面的命令啦!

进入命令窗口(Win + R),连接数据库 mysql -hlocalhost -uroot -p,回车,输入密码,回车,如图:
IDEA连接mysql报错,Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' prope

2,继续输入 show variables like’%time_zone’; (注意不要漏掉后面的分号),回车,如图:

IDEA连接mysql报错,Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' prope

显示 SYSTEM 就是没有设置时区啦。

3,现在我们来设置时区。

输入set global time_zone = ‘+8:00’; 注意不要漏掉后面的分号),回车,如图:

IDEA连接mysql报错,Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' prope

这便是设置成功啦!

这时你重新连接下数据库,也许能连接成功!如果没有,就继续往下走!

IDEA连接mysql报错,Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' prope

如果,你选的是MySQL,

数据库又是其他版本的,也没关系。

在驱动列表里找到 MySQL ,右边Driver files 里,选择一下你需要的版本,保存就可以了。

IDEA连接mysql报错,Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' prope