当前位置:   article > 正文

MySQL server time zone 报错 (MySQL时区问题)_mysql servertimezone not support

mysql servertimezone not support
  1. 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.
  2. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_181]
  3. at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_181]
  4. at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_181]
  5. at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_181]

解决的方法异常信息里已经给出:  配置server或者JDBC驱动来指定时区

  • 配置JDBC驱动指定时区

jdbc:mysql://127.0.0.1:3306/local?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8

实际是把GMT+8(北京时间)作为参数传递, 也可以传入Linux中的timezone (Asia/Shanghai)...

 

  • 修改MySQL的时区

  1. --查看当前server时区
  2. SHOW VARIABLES LIKE '%time_zone%';
  3. --设置全局时区为北京时间
  4. SET GLOBAL time_zone='+8:00';
  5. --设置当前session时区为北京时间
  6. SET time_zone='+8:00';
  • 修改mysql的配置文件

Windows -- my.ini

Linux -- my.cnf

在配置文件中加上

default-time_zone = '+8:00'

(注意:修改配置文件不是立即生效, 添加参数后需要重启mysql服务(进程))

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/空白诗007/article/detail/795361
推荐阅读
相关标签
  

闽ICP备14008679号