Build a double master, suddenly think of if the table set the self-increment primary key, when the business at the same time to insert a pair of data in a double library, what is the situation like?
For example, a table data on the main library A and the main library B is: ' Ninhao '. When the business writes data at the same time, the data of the library A is ' new Nihao '? What is the data on the main library B? The primary key is also 13?
It is recommended to be similar to two-master scenarios:
Set the value of offset and increment in advance, i.e. implement the initial value and step size of the self-increment field. The main library A is odd-numbered, and the main library B starts with an even number. Both use the same step size.
1), set the primary home server's self-growth offset location is different:
A:auto_increment_offset=3
B:auto_increment_offset=4
2), set the primary master server step is the same:
? auto_increment_increment=2
The double-master problem was solved. Another idea: If the business update a data at the same time, now is God's situation?
There is also a problem, the main library A to create a library, create a table, insert data, the main library b directly error.
Follow the next blog: Use crontab to simulate simultaneous update.
How mysql dual master resolves a primary key conflict problem