mysql的时区错误问题: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one

最近很多次遇到

The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone

这个问题,
报错为:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!### The error may exist in com/wj/mapper/UserLoginMapper.xml### The error may involve com.wj.mapper.UserLoginMapper.selectByName### The error occurred while executing a query### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!

    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)

    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)

    javax.servlet.http.HttpServlet.service(HttpServlet.java:650)

    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)

    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)

  root cause

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.

    com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:127)

    com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95)

    com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:87)

    com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:61)

    com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:71)

    com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76)

    com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:862)

    com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:444)

    com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:230)

    com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:226)

    com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)

    com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)

    com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)

    com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)

    com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)

    com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)

    com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)

    com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)

    com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)

网上说法也很多,经过测试,有效的一个办法如下:


mysql的时区错误问题: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one_第1张图片
image.png

即可解决这个错误!

情况二

mysql serverTimezone useSSL 時差

剛開始遇到這個問題很驚訝,爲何我往數據庫添加的時間明明是當前時間(例:2019-3-03-29 09:00:00),然而數據庫中顯示的時間卻少了8個小時(例:2019-3-03-29 01:00:00)。很明顯,8個小時的時差,而且北京時區爲東八區,這應該就是時區設置問題了。

查看了一下項目中的數據庫連接設置,如下:

hibernate.dialect=org.hibernate.dialect.MySQL8Dialect

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql:/127.0.0.1:8080/test?useSSL=false&serverTimezone=UTC
jdbc.username=root
jdbc.password=root

發現其中serverTimezone設置的值爲UTC,UTC代表的是全球標準時間 ,而我們所在的時區是東八區,領先UTC八個小時,這就是導致問題所在了。

解決方法:將serverTimezone設置爲北京時間或者上海時間來解決。

//北京時間東八區
serverTimezone=GMT%2B8 
//上海時間
serverTimezone=Asia/Shanghai

你可能感兴趣的:(mysql的时区错误问题: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one)