0

I have a remote MySQL DB in the cloud on JAWSDB.

I have createdAt and updatedAt timestamps for records that are in UTC TZ.

I'll backup these DBs using mysqldump -h HOST -u USER -p > backup.sql. I then restore these to a local MySQL Server using mysql -u USERNAME -p DB_NAME < backup.sql

However, upon inspecting the new local backup...I notice that the createdAt timestamps are for my local TZ (EST and so currently 5hrs before the UTC version that are actually in JAWSDB). The updatedAt timestamps are still in UTC though.

Here's how I created those timestamp fields btw.

 `createdAt` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
 `updatedAt` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

So it seems like the restore of the dump is converting from UTC to EST just for the createdAt field. Could this be due to an engine or mysql version mismatch between JawsDB and my local server?

Any insights? Thanks!

1

From MySQL documentation

MySQL converts TIMESTAMP values from the current time zone to UTC for storage, and back from UTC to the current time zone for retrieval. (This does not occur for other types such as DATETIME.) By default, the current time zone for each connection is the server's time. The time zone can be set on a per-connection basis. As long as the time zone setting remains constant, you get back the same value you store. If you store a TIMESTAMP value, and then change the time zone and retrieve the value, the retrieved value is different from the value you stored. This occurs because the same time zone was not used for conversion in both directions. The current time zone is available as the value of the time_zone system variable. For more information, see Section 5.1.15, “MySQL Server Time Zone Support”.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.