views:

50

answers:

2

From what I learned, a MySQL MASTER server is one that can both read and write. Correct?

My question is: Suppose you have 2 MySQL master-write servers (and many slave-read servers).

How can you solve the problem of auto-increment? How do you sync it? Suppose you are writing to both the Master1 and Master2...how will you sync it so that the auto-increment is consistent? Can someone please explain the solution to this in a simple sense.

+1  A: 

You set server #1 to use odd numbered auto increment values and server number #2 to use even numbered.

# server 1 
auto_increment_increment 2                                
auto_increment_offset    1   

# server 2
auto_increment_increment 2                                
auto_increment_offset    2

There's a linux how-to which outlines the process. See also MySQL docs on this.

martin clayton
But what if one server dies? Then...the server left standing will continue to increment odd?
TIMEX
Yes, that would be how it is configured. You would get gaps.
martin clayton
Is Gaps OKay ??
TIMEX
Maybe. Depends on how you use the autoincrement values. If you need them to be monotonically increasing with no gaps, you have an issue. If they are unique internal ids in the system, which is usually the case, then gaps are no big deal.
martin clayton
A: 

Gaps should be okay if your system doesn't need it to be. As soon as you hit the limit of INT or BIGINT you should be ready with a data warehousing setup so you can offload your old data and get ready rollover back to the base offset values. On a write-intensive application, you'll need to be prepared and be able to offload old data as soon as possible.

rmartinez