问题
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:
- Are both settings timezone aware?
- If not, which is not?
- How can I tell it to be? :-)
- 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