首页 > 技术文章 > java.sql.SQLException: The server time zone value 'EDT' is unrecognized or represents more than one time zone

qq931399960 2020-07-30 09:27 原文

异常信息

java.sql.SQLException: The server time zone value 'EDT' 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.

异常信息的提示已经很明显了,去数据库中查找时区

show variables like '%time_zone%';

 

 mysql默认使用了系统时区

查看当前的系统时区,可以发现当前的Time zone为EDT时区

 

设置时区为:Asia/Shanghai

timedatectl set-timezone "Asia/Shanghai"

 

 重启mysql,问题解决

 

但是需要注意的是,要保证当前服务器是可以连外网的,并且要开启ntpd,可以通过如下命令检查和启动ntpd

systemctl status ntpd
systemctl start ntpd

 

如果NTP enabl.ed为false,可以通过如下命令设置

timedatectl set-ntp yes

 

也可以通过设置mysql时区来解决问题

mysql> set global time_zone='+8:00';
Query OK, 0 rows affected (0.00 sec)

 

永久生效,可以在配置文件中添加配置

[mysqld] 
default-time-zone='+08:00'

 

也可以通过如下命令将配置还原为初始配置

mysql> set global time_zone='SYSTEM';
Query OK, 0 rows affected (0.00 sec)

 

推荐阅读