背景知识:

我有一个运行在Tomcat 7上的Java 1.6 web应用程序。数据库为MySQL 5.5。之前,我使用Mysql JDBC驱动程序5.1.23连接到DB。一切工作。我最近升级到Mysql JDBC驱动程序5.1.33。升级后,Tomcat在启动应用程序时会抛出这个错误。

WARNING: Unexpected exception resolving reference
java.sql.SQLException: The server timezone value 'UTC' is unrecognized or represents
  more than one timezone. You must configure either the server or JDBC driver (via
  the serverTimezone configuration property) to use a more specifc timezone value if
  you want to utilize timezone support.

为什么会这样?


当前回答

我只需要在application.properties上添加serverTimeZone=UTC就可以了。 spring.datasource.url = jdbc: mysql: / / localhost / db吗?serverTimezone = UTC

其他回答

将服务器时间设置为UTC没有影响(例如使用jdbc:mysql://localhost:3306/myschema?serverTimezone=UTC,即使您的应用程序/数据库服务器不在这个时区。重要的是应用程序连接字符串+数据库要与相同的时区同步。

换句话说,只需在数据库服务器上使用不同的时区设置serverTimezone=UTC,就可以转移从数据库中提取的任何日期

我得到的错误类似于你的,但我的服务器时区值是'Afr。舟状骨的西部省 所以我做了这些步骤:

MyError (IntelliJ IDEA社区版):

    InvalidConnectionAttributeException: The server time zone value 'Afr. centrale Ouest' 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 u....

当我把mysql服务器升级到SQL server 8.0 (MYSQL80)时,我遇到了这个问题。

这个问题最简单的解决方案是在MYSQL Workbench中编写下面的命令-

  SET GLOBAL time_zone = '+1:00'

时区之后的值将等于您所在时区的GMT+/-差值。上面的例子是北非(GMT+1:00) /或印度(GMT+5:30)。 这将解决问题。

在Mysql Workbench中输入以下代码并执行查询

[问题/问题的来源链接]

[答案来源链接]

[解决方案截图]

我解决了把下面的连接字符串在URL

jdbc:mysql://localhost:3306/db?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC

我在LibreOffice基地也遇到了同样的问题。所以我只是在连接字符串中指定了一个非“夏时制时区”。

我尝试没有“&serverTimezone=MST”,但也失败了。

我还尝试了“&serverTimezone=MDT”,失败了,所以出于某种原因,它不喜欢夏令时!

我迟到了,但如果你正在努力克服以下错误并使用数据源(javax.sql.DataSource):

The server time zone value 'CEST' is unrecognized or represents more than one time zone.

设置以下行以消除错误:

MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setServerTimezone("UTC");