Transfer from
https://njs375666635.iteye.com/blog/2242067
Mutual support multi-master and master-slave replication there are some differences, because can have write access to the server in a multi-master, since it is designed to increase repeat the question
Problems (from multiple primary growth ID repeat)
1: First, we synchronize A, the table structure B Test
2: stopped A, the data table of test (from the presence of growth ID) on the insert operation B, inserted ID is returned . 1
3: stopped B, insertion operations on the data table test (since the presence of growth ID) in a, the returned ID insert also 1.
4: then we start at the same time a, B, primary key ID will be repeated
solution:
as long as we ensure that different inserted on both servers from growth data on it
, such as: a check odd ID, B plug even-ID, of course, if the server and more, you can define the algorithm, as long as different on it
where we are a, Add the B parameter, in order to achieve parity insertion
a: Add parameters the my.cnf
auto_increment_offset = 1
auto_increment_increment 2 =
value a such that the generated field auto_increment: 1, 3, 5, 7, ... of the odd-number ID
B: my. Add parameters CNF
auto_increment_offset = 2
auto_increment_increment = 2
AUTO_INCREMENT field B produced by such values are: 2, 4, 6, 8, ... and so the even the ID
As can be seen, your auto_increment field will not be repeated across different servers, so Master-Master structure would be no problem. Of course, you can also use three, four, or N servers, as long as auto_increment_increment = N then set about auto_increment_offset to the appropriate initial value on it, so that we can have dozens of MySQL master server at the same time, and since growth will not repeat the ID.
1: First, we synchronize A, the table structure B Test
2: stopped A, the data table of test (from the presence of growth ID) on the insert operation B, inserted ID is returned . 1
3: stopped B, insertion operations on the data table test (since the presence of growth ID) in a, the returned ID insert also 1.
4: then we start at the same time a, B, primary key ID will be repeated
solution:
as long as we ensure that different inserted on both servers from growth data on it
, such as: a check odd ID, B plug even-ID, of course, if the server and more, you can define the algorithm, as long as different on it
where we are a, Add the B parameter, in order to achieve parity insertion
a: Add parameters the my.cnf
auto_increment_offset = 1
auto_increment_increment 2 =
value a such that the generated field auto_increment: 1, 3, 5, 7, ... of the odd-number ID
B: my. Add parameters CNF
auto_increment_offset = 2
auto_increment_increment = 2
AUTO_INCREMENT field B produced by such values are: 2, 4, 6, 8, ... and so the even the ID
As can be seen, your auto_increment field will not be repeated across different servers, so Master-Master structure would be no problem. Of course, you can also use three, four, or N servers, as long as auto_increment_increment = N then set about auto_increment_offset to the appropriate initial value on it, so that we can have dozens of MySQL master server at the same time, and since growth will not repeat the ID.