As you can see, your auto_increment field will never be repeated among different servers, so there is no problem with the Master-Master structure. You can also use
As you can see, your auto_increment field will never be repeated among different servers, so there is no problem with the Master-Master structure. You can also use
There are some differences between multi-master-slave mutual backup and master-slave replication, because the multi-master can have write permissions on the server, so it is designed to repeat the problem from self-growth.
Problem (Multiple Primary auto-growth IDs are repeated)
1: First, we use the test table structure of A and B.
2: Drop A, insert the data table test (with an auto-increment ID) on B, and return the insert ID as 1.
3: Stop B and insert the data table test (with an auto-increment ID) on Table A. The returned insert ID is also 1.
4: Then we start both A and B, and duplicate primary key IDs will appear.
Solution:
We only need to ensure that the auto-growth data inserted on the two servers is different.
For example, if A queries an odd ID and B inserts an even ID, you can define an algorithm if there are many servers.
Here we add parameters on a and B to implement parity insertion.
A: Add parameters to my. cnf.
Auto_increment_offset = 1
Auto_increment_increment = 2
In this case, the auto_increment field of a produces the following values: 1, 3, 5, 7 ,... And so on.
B: Add parameters to my. cnf.
Auto_increment_offset = 2
Auto_increment_increment = 2
In this way, the value produced by the auto_increment field of B is: 2, 4, 6, 8 ,... An even number of IDs.
As you can see, your auto_increment field will never be repeated among different servers, so there is no problem with the Master-Master structure. Of course, you can also use 3, 4, or N servers. You only need to ensure auto_increment_increment = N and then set auto_increment_offset to the appropriate initial value, our MySQL can have dozens of Master servers at the same time, without repeated self-growth IDs.