问题描述:

在使用IntelliJ IDEA关联数据库时,提示如下错误:
ERROR:Server returns invalid timezone. Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually. .
中文翻译:
服务器返回无效时区。转到“高级”选项卡并手动设置“服务器时区”属性。
Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually. .

解决办法:

原因:

中国所在时区是UTC-8,刚好和格林威治时间差8个小时,MySql默认的时区是UTC时区,比北京时间晚8个小时,因而导致时区错误,所以要修改MySql的时区设置。

步骤:

  1. 进入DOS命令窗口(Win + R --> cmd --> 回车);
  2. 连接数据库(mysql -u root -p --> 回车 --> 输入密码 --> 回车)
  3. 查看MySql的时区设置( show variables like ‘%time_zone%’; ),注意后面有分号,若为SYSTEM则未设置时区;
    Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually. .
  4. 设置时区( set global time_zone = ‘+8:00’; ),注意后面有分号;
    Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually. .
  5. 关闭DOS命令窗口,重复步骤1、2、3,再次连接数据库,查看时区设置是否成功;若不重连数据库,时区设置依然显示SYSTEM;重连后,成功设置的时区显示如下:
    Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually. .
  6. 再次使用IDEA关联数据库,点击Test Connection,若显示MySql版本等相关信息,则表示连接数据库成功。
    Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually. .

相关文章: