Resolves key-value conflicts between two MySQL Databases during bidirectional synchronization.

Source: Internet
Author: User
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.

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.