MySQL off-site replication and timezones
Recently we were doing some testing on a mysql slave server which was located at an off-site location from the master server. While the on-site slave was having no problems replicating, the off-site slave would once a day break replication on a duplicate entry error because of a unique key insert problem.
This was very weird, especially because the on-site slave was having no trouble at all. After some brainstorming aided by percona, we realized the cause. The off-site slave was in a different timezone than the other master and slave. This fact together with the fact that we had a unique key that contained curdate(), caused the following scenario:
- On January 3, 23:57, there was an insert on table t, unique key was 2009-01-03.
- On January 4, 00:01, there was an insert on table t, unique key was 2009-01-04
No problem, but — times are replicated as timestamps, so on the off-site slave, which was 1 hour ahead (EST instead of CST):
- First insert was replicated as January 4, 00:57, insert on table t, unique key 2009-01-04
- Second insert was replicated as January 4, 01:01, insert on table t, and error on unique key for 2009-01-04
The solution is either to set the whole machine’s timezone to the timezone of the master you’re replicating, or using the same time-zone and default-time-zone settings for the mysql server.
About this entry
You’re currently reading “MySQL off-site replication and timezones,” an entry on Life Scaling
- Published:
- 1.15.09 / 9am
- Tags:
- MySQL, replication, slave, timezone
Follow me on Twitter: @orensol
- Hey #AWS, how about improving EBS? Maybe change underlying hardware to SSD, and make it more predictable? http://j.mp/gRG2b9
- @sebastianstadil it is indeed beautiful. It really depends on your use case and space to put it. I don't like when a printer crowds my desk.
- @sebastianstadil get one with builtin wifi (like hp1102w). Then you can throw it off wherever it fits around the house/office.
- Facebook Engineering Blog is one of the most incredible things to read on the Internet. http://j.mp/e7gFjg
- @dvirsky hehe, I read it as two different girlfriends, which made your tweet much more heart warming.

I am Oren, and this is my blog. I am a techie entrepreneur, co-founder & CTO of
1 Comment
Jump to comment form | comments rss [?] | trackback uri [?]