JDBC连接mysql出现时区错误

 报错信息:

  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设置时区与当前系统时区不符,需要手动修改时区为东八区 "+8:00" 。

方法一:

  1、在 cmd 中登陆mysql后输入 select curtime(); 或select now();  -- 查看当地时间

    

 

  2、查看当前时区(show variables like "%time_zone%")

    

  system_time_zone 为空表示当前mysql时间与系统一致,time_zone 为SYSTEM表示当前使用的时区为SYSTEM时区

  3、将时区更改为现在所在时区(东八区)

    1. set time_zone="+8:00"; 只能修改当前会话窗口的时区

    

    2. set global time_zone="+8:00"; 修改全局时区

    

  4、更改完成

    

 

 

方法二:

  在连接mysql数据库语句的url后面添加:

     ?useSSL=true&serverTimezone=UTC 

 

方法三:

  1. 在MySQL的安装目录中找到 my.ini 文件夹

  2. 打开my.ini,找到mysql,在mysql下面输入

     default-time-zone = '+8:00' 

  3. 点击保存,重启mysql服务

   

  参考博客:https://blog.csdn.net/weixin_44218204/article/details/85785761?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.edu_weight&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.edu_weight

posted @ 2020-10-15 21:57  水水君  阅读(1)  评论(0)    收藏  举报