解决:java.sql.SQLException: The server time zone value xxxxx is unrecognized or represents more tha

异常信息:Exception in thread “main” java.lang.RuntimeException: java.sql.SQLException: 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时区不同,修改为本地时区即可

解决方法一:在代码中更改时区,但这样做治标不治本,每次写代码都要加上去

在代码URL后面加入: ?serverTimezone=GMT%2B8

如:“jdbc:mysql://localhost:3306/mydb?serverTimezone=GMT%2B8”

解决方法二:直接对数据库时区进行修改,修改完成后以后就不需要再做更改了

win + R ------》输入cmd

输入mysql账号和密码(其中root为用户名,123456为密码,可根据实际情况填)

mysql -uroot -p123456

解决:java.sql.SQLException: The server time zone value xxxxx is unrecognized or represents more tha

查看现在的时区

show variables like ‘%time_zone%’;

解决:java.sql.SQLException: The server time zone value xxxxx is unrecognized or represents more tha

修改为本地时区(以中国时区为例:需要在原时区上+8:00)

set global time_zone = ‘+8:00’;

解决:java.sql.SQLException: The server time zone value xxxxx is unrecognized or represents more tha

修改成功,若需查看,需关闭命令(cmd)窗口再打开重新查看

解决:java.sql.SQLException: The server time zone value xxxxx is unrecognized or represents more tha