在 jdbcUrl 连接 url 中设置 属性 serverTimezone 是否会影响 mysql 数据库中时间戳值的 read/write?
Does setting the property serverTimezone in jdbcUrl connection url affects read/write of timestamp value from mysql database?
我的 mysql 服务器是 运行 PDT(-07:00) 时区
我的代码是 运行 在 UTC 时区的服务器上
我正在使用 mysql-连接器-java 版本“8”
如果我在 jdbcUrl
连接 url 中设置 属性 serverTimezone=UTC
,是否
- 影响从 mysql 数据库读取的时间戳值?
- 如果 (1) 是,那么如何?
If I set property serverTimezone=UTC in jdbcUrl connection url, does
it affect the timestamp value being read from mysql database?
是的,确实如此。我在下面引用 https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-other-changes.html:
的摘录,而不是我的解释
The server's time zone is overridden by setting the Connector/J
connection property serverTimezone (for example,
serverTimezone=Europe/Paris).
建议:我建议您使用serverTimezone=UTC
,然后在您的应用程序代码中将检索到的时间戳转换为所需的时区。同样,为了支持这一建议,我在下面引用了 https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-usagenotes-known-issues-limitations.html:
的摘录
When Connector/J retrieves timestamps for a daylight saving time (DST)
switch day using the getTimeStamp() method on the result set, some of
the returned values might be wrong. The errors can be avoided by using
the following connection options when connecting to a database:
serverTimezone=UTC
我的 mysql 服务器是 运行 PDT(-07:00) 时区 我的代码是 运行 在 UTC 时区的服务器上 我正在使用 mysql-连接器-java 版本“8”
如果我在 jdbcUrl
连接 url 中设置 属性 serverTimezone=UTC
,是否
- 影响从 mysql 数据库读取的时间戳值?
- 如果 (1) 是,那么如何?
If I set property serverTimezone=UTC in jdbcUrl connection url, does it affect the timestamp value being read from mysql database?
是的,确实如此。我在下面引用 https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-other-changes.html:
的摘录,而不是我的解释The server's time zone is overridden by setting the Connector/J connection property serverTimezone (for example, serverTimezone=Europe/Paris).
建议:我建议您使用serverTimezone=UTC
,然后在您的应用程序代码中将检索到的时间戳转换为所需的时区。同样,为了支持这一建议,我在下面引用了 https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-usagenotes-known-issues-limitations.html:
When Connector/J retrieves timestamps for a daylight saving time (DST) switch day using the getTimeStamp() method on the result set, some of the returned values might be wrong. The errors can be avoided by using the following connection options when connecting to a database:
serverTimezone=UTC