zoukankan      html  css  js  c++  java
  • Mysql连接出现时区问题

    错误提示:

    The server time zone value ‘¥x¥_¼Ð·Ç®É¶¡’ 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的连接通常都是:

    jdbc:mysql://localhost/blog?useUnicode=true&characterEncoding=utf8

    直接指定字符集就行了,今天报了这个错误,找了下原因,是因为时区的问题。

    方法一:

    修改url为

    jdbc:mysql://localhost/blog?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC

    方法二:

    1.在mysql的命令模式下使用
    mysql > select CURTIME();
    

    mysql > select now();
    

    看当前时间是否正确,可以看到mysql当前使用的是那一个时区的时间。

    2.在Mysql命令行中更改时区
    mysql > SET time_zone = '+8:00'; # 此为北京时,我们所在东8区
    
    mysql> flush privileges; # 立即生效
    

    此时mysql时区已更改正确,与系统时区都使用为 Shanghai时间了。
    这种方法好像只能在终端上使用,退出终端后时间又会变成原来的,看来只能重启mysql了。

    3.重启mysql也应没有问题,此时mysql会主动读取系统时间。
  • 相关阅读:
    SpringMVC执行原理
    Hello SpringMVC 注解版
    Hello SpringMVC 注解版
    Mybatis一对多和多对一处理
    2020-08-08日报博客
    2020-08-07日报博客
    《大道至简》读后感
    2020-08-06日报博客
    2020-08-05日报博客
    2020-08-04日报博客
  • 原文地址:https://www.cnblogs.com/mengw/p/12213093.html
Copyright © 2011-2022 走看看