其他分享
首页 > 其他分享> > The server time zone value ‘�й���׼ʱ��‘ is unrecognized or represents more than one time zone......

The server time zone value ‘�й���׼ʱ��‘ is unrecognized or represents more than one time zone......

作者:互联网

spark写入mysql报错如下

Caused by :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.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85)
at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:132)
at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2118)
at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2142)
at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1310)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:967)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826)
… 8 more

问题原因

时区问题(高版本的MySQL在连接时需要设置时区)

解决方法

在url中添加 serverTimezone=GMT%2B8,如下

"jdbc:mysql://localhost:3306/database?serverTimezone=GMT%2B8"

标签:represents,java,zone,cj,time,ConnectionImpl,mysql,com
来源: https://blog.csdn.net/weixin_52299264/article/details/122265842