连接mysql的时候报错,发现并不是代码的问题。
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.
从错误即可知道是时区的错误,因此只要将时区设置为你当前系统时区即可。有如下两种解决方法:
(1)在数据库 URL中设置serverTimezone属性:
在URL后面添加serverTimezone=GMT%2B8
jdbc:mysql://localhost:3306/dashuju?useSSL=false&serverTimezone=GMT%2B8;
这里的 GMT%2B8 代表是东八区。
(2)或者使用root用户登录mysql,执行下面命令:
SHOW VARIABLES LIKE '%time_zone%';
SET GLOBAL time_zone = '+8:00';
电脑系统为北京时区,执行成功后连接数据库运行,一切正常。