Timezone awareness differences between System TZ and DB TZ?

北城以北 提交于 2019-12-11 08:01:59

问题


I am currently migrating a database from a local MySQL host to Aurora in RDS.

Checking the time zone settings on both systems using:

SELECT @@system_time_zone, @@global.time_zone, @@session.time_zone, NOW(), UTC_TIMESTAMP();

Local Mysql

+--------------------+--------------------+---------------------+---------------------+---------------------+
| @@system_time_zone | @@global.time_zone | @@session.time_zone | NOW()               | UTC_TIMESTAMP()     |
+--------------------+--------------------+---------------------+---------------------+---------------------+
| AEDT               | SYSTEM             | SYSTEM              | 2017-12-07 15:05:29 | 2017-12-07 04:05:29 |
+--------------------+--------------------+---------------------+---------------------+---------------------+

RDS (Aurora)

+--------------------+--------------------+---------------------+---------------------+---------------------+
| @@system_time_zone | @@global.time_zone | @@session.time_zone | NOW()               | UTC_TIMESTAMP()     |
+--------------------+--------------------+---------------------+---------------------+---------------------+
| UTC                | Australia/Sydney   | Australia/Sydney    | 2017-12-07 15:05:29 | 2017-12-07 04:05:29 |
+--------------------+--------------------+---------------------+---------------------+---------------------+

Issue:

The timestamps after 1st October (that's when DST happens) are equal, but differ by one hour before, see below:

Local MySQL

+--------+---------------------+---------------------+
| id     | created_at          | updated_at          |
+--------+---------------------+---------------------+
|      1 | 2017-08-21 05:08:02 | 2017-08-21 05:20:01 |
|      2 | 2017-08-21 05:08:02 | 2017-08-21 05:20:01 |
|      3 | 2017-08-21 05:08:02 | 2017-08-21 05:20:01 |
|  30000 | 2017-09-07 00:45:02 | 2017-09-07 01:10:03 |
|  98350 | 2017-09-30 19:15:03 | 2017-09-30 19:40:03 |
|  98357 | 2017-10-01 08:00:02 | 2017-10-01 08:25:03 |
|  98358 | 2017-10-01 08:00:02 | 2017-10-01 08:25:03 |
|  98359 | 2017-10-01 08:00:02 | 2017-10-01 08:25:03 |
| 100361 | 2017-10-01 19:05:03 | 2017-10-01 19:30:03 |
| 100411 | 2017-10-01 19:10:04 | 2017-10-01 19:35:03 |
| 100412 | 2017-10-01 19:10:04 | 2017-10-01 19:35:03 |
| 394449 | 2017-12-07 08:30:03 | 2017-12-07 09:00:04 |
| 394472 | 2017-12-07 08:30:03 | 2017-12-07 09:00:08 |
+--------+---------------------+---------------------+

RDS (Aurora)

+--------+---------------------+---------------------+
| id     | created_at          | updated_at          |
+--------+---------------------+---------------------+
|      1 | 2017-08-21 06:08:02 | 2017-08-21 06:20:01 |
|      2 | 2017-08-21 06:08:02 | 2017-08-21 06:20:01 |
|      3 | 2017-08-21 06:08:02 | 2017-08-21 06:20:01 |
|  30000 | 2017-09-07 01:45:02 | 2017-09-07 02:10:03 |
|  98350 | 2017-09-30 20:15:03 | 2017-09-30 20:40:03 |
|  98357 | 2017-10-01 08:00:02 | 2017-10-01 08:25:03 |
|  98358 | 2017-10-01 08:00:02 | 2017-10-01 08:25:03 |
|  98359 | 2017-10-01 08:00:02 | 2017-10-01 08:25:03 |
| 100361 | 2017-10-01 19:05:03 | 2017-10-01 19:30:03 |
| 100411 | 2017-10-01 19:10:04 | 2017-10-01 19:35:03 |
| 100412 | 2017-10-01 19:10:04 | 2017-10-01 19:35:03 |
| 394449 | 2017-12-07 08:30:03 | 2017-12-07 09:00:04 |
| 394472 | 2017-12-07 08:30:03 | 2017-12-07 09:00:08 |
+--------+---------------------+---------------------+

Questions:

  1. Are both settings timezone aware?
  2. If not, which is not?
  3. How can I tell it to be? :-)
  4. Afaik MySQL stores timestamps in UTC and converts them transparently upon read and write based on the timezone (see this SO reply for more information). Is there any way to get the raw value of a timestamp field without any (transparent or non transparent) conversions?

来源:https://stackoverflow.com/questions/47687470/timezone-awareness-differences-between-system-tz-and-db-tz

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!