java连接mysql-----时钟错误
Posted 8023cyy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java连接mysql-----时钟错误相关的知识,希望对你有一定的参考价值。
弄好驱动和连接后,发现运行测试代码还是有错误:
具体提示的异常信息是:
java.sql.SQLException: 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 com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at test.Conn.getConnection(Conn.java:23)
at test.testConnection.main(testConnection.java:7)
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(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
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:2234)
at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2258)
at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1319)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:966)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)
... 7 more
经过百度的查找,最后找到解决方案:
1 启动MySQL,同时登陆mysql,查看当前的时区信息(查看可做可不做)
2 修改MySQL时区
3 查看修改后的时区信息(可做可不做)
至此解决了时区不一致的问题。
具体命令:
mysql -u root -p 登陆mysql;
show variables like ‘%time_zone%‘; 查看时区信息
set global time_zone=‘+8:00‘; 修改为东八区的信息
exit 退出mysql命令
以上是关于java连接mysql-----时钟错误的主要内容,如果未能解决你的问题,请参考以下文章
PHP连接mysql时mysql_connect()函数不可用,报500错误
连接数据库报错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mys