一、错误消息

  1. java.lang.RuntimeException: com.mysql.cj.exceptions.InvalidConnectionAttributeException: 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)
  3. at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  4. at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  5. at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  6. at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
  7. at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85)
  8. at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:132)
  9. at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2241)
  10. at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2265)
  11. at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1319)
  12. at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:868)
  13. at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:830)
  14. at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
  15. at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
  16. at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
  17. at com.intellij.database.remote.jdbc.impl.RemoteDriverImpl.connect(RemoteDriverImpl.java:41)
  18. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  19. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  20. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  21. at java.lang.reflect.Method.invoke(Method.java:498)
  22. at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
  23. at sun.rmi.transport.Transport$1.run(Transport.java:200)
  24. at sun.rmi.transport.Transport$1.run(Transport.java:197)
  25. at java.security.AccessController.doPrivileged(Native Method)
  26. at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
  27. at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
  28. at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
  29. at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
  30. at java.security.AccessController.doPrivileged(Native Method)
  31. at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
  32. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  33. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  34. at java.lang.Thread.run(Thread.java:748) (no stack trace).
  35. com.mysql.cj.exceptions.InvalidConnectionAttributeException: 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.
  36. .

二、原因

出错的原因是mysql的时区值设置的不正确。mysql默认的时区值是美国,中国的时区要比美国晚8小时,需要采用+8:00的格式。

三、解决办法

1、查看mysql当前时区

show variables like'%time_zone'

image.png

2、修改mysql配置文件

修改配置文件 my.ini

[mysqld]
## 设置时区
default-time-zone='+08:00'

3、重启mysql

4、查看数据库时区

image.png

三、修改url

serverTimezone=Asia/Shanghai