I'm having issues with timezones with MYSQL. Right now, I'm dumping the data via mysqldump, as such:
mysqldump -uuser -ppass --tab c:/temp --skip-dump-date dbName
This works exactly as intended, with the data in the database matching the .txt files that are generated. The problem comes with importing the data. To get around some foreign key issues during the import phase, I'm using the following code:
SET FOREIGN_KEY_CHECKS = 0;
LOAD DATA LOCAL INFILE 'c:/temp/tableName.txt' INTO TABLE tableName;
SET FOREIGN_KEY_CHECKS = 1;
This also has no issues, except afterwards when I check the database, all the TIMESTAMP
s are shifted by 5 hours forwards. I know this has to be a problem with time zones (I'm UTC-05:00, so the shift time makes sense), but I don't understand what should be done to stop the database from assuming that a shift in time needs to be done.
Along my searches for answers, I came across a similar SO problem, but the issue was backwards. Importing was fine, exporting was shifted. MySQL data export changes times
Furthermore, I have seen some suggestions to look at this information in MYSQL, but I don't exactly know what I should do with this information now that I have it.
SELECT @@global.time_zone, @@session.time_zone;
Gives me:
SYSTEM +00:00
Is there a way to tell MYSQL to import without changing TIMESTAMP
s? Should I change some sort of time zone setting? If so, should I change it for import, or export? I'm not planning on moving the database across any time zones.
UPDATE 1
In the mean time until I know best practice, I have tried the following change directly before using the block of LOAD DATA
commands:
SET TIME_ZONE = '+00:00';
This has solved my problem (where I expect my dump to be the same as the files I used to create the database). Afterwards, I change the time back to -05:00
, but I'm not sure if it was necessary.