The solution of the key-value conflict problem of MySQL bidirectional synchronization sharing _mysql
Source: Internet
Author: User
Problems that occur (multiple-master self-growth ID duplicates)
1: First we pass the test table structure of A,B
2: Off A, in B on the data table test (there is a self-growth ID) to perform an insert operation, return the insertion ID of 1
3: After stopping B, in a on the data table test (there is a self-growth ID) to perform the insert operation, the return of the insertion ID is also 1
4: Then we start the a,b at the same time, the primary key ID duplicate will appear
Workaround:
All we have to do is make sure that the growth data inserted on both servers is different.
such as: A Chachi number id,b interpolation even ID, of course, if more than the server, you can define the algorithm, as long as the difference can be
Here we add the parameters on a, b to implement the parity insertion
Add Parameters on A:MY.CNF
Auto_increment_offset = 1
Auto_increment_increment = 2
Such a auto_increment field produces a value of: 1, 3, 5, 7, ... Odd ID.
Add Parameters on B:MY.CNF
Auto_increment_offset = 2
Auto_increment_increment = 2
In this case, the auto_increment field of B produces a value of: 2, 4, 6, 8, ... Equal even ID.
As you can see, your auto_increment field is never duplicated between different servers, so there's no problem with the master-master structure. Of course, you can also use 3, 4, or N servers, as long as the guarantee auto_increment_increment = N again set the Auto_increment_offset for the appropriate initial value on it, that, Our MySQL can have dozens of primary servers at the same time without duplication of growth IDs.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service