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目录路径。

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值