The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized 偶然遇到的mysql时区问题

因为换了个电脑用,运行时报了个很少见的异常。如下:

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary. 异常

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

异常 

看着不像是sql的问题,检查了下代码,发现也没明显啥问题,就去查了下。

果然有遇到相同问题的,

1的异常是因为所用的Mysql驱动包已经不推荐之前用的mysql驱动类,推荐使用新的mysql驱动类

2的异常是因为mysql时区问题

  就是上面标红的SQL异常,我们需要在数据库 URL中设置serverTimezone属性:

static final String DB_URL = "jdbc:mysql://localhost:3306/RUNOOB" +
        "?serverTimezone=GMT%2B8";
 这里的 GMT%2B8 代表是东八区。

当然有更好的办法就是win + R进入cmd窗口,mysql -u root -p 进入mysql ,然后输入 set  global time_zone = '+8:00';

尴尬的是登陆时提示没用mysql命令,果然环境变量中path路径中需要添加mysql的bin目录路径。

然后重新执行下上述命令即可。

猜你喜欢

转载自blog.csdn.net/java_xth/article/details/83656797