Mysql dual-master self-growth conflict handling

Source: Internet
Author: User

There are some differences between the two-master auto-growth conflicts in Mysql and the two-master-slave replication, because multiple masters can have write permissions on the server, so the problems that arise from the design to the auto-growth repetition problem (Multi-master auto-growth ID duplication) 1: First, we use the test table structure of A and B 2: Drop, perform the insert operation on the data table test (with an auto-increment ID) on table B, return the insert ID as 1 3: Stop B, and test (with an auto-increment ID) on Table) when the insert operation is executed, the returned insert ID is also 1 4: Then we start A, B at the same time, the primary key ID will be repeated solution: we only need to ensure that the self-growth data inserted on the two servers is different. For example, A queries the odd ID and B inserts the even ID. Of course, if there are many servers, you can define an algorithm, we can add parameters on a and B to achieve parity insertion. added the auto_increment_offset = 1 auto_increment_increment = 2 to the cnf. Values: 1, 3, 5, 7 ,... The values produced by the auto_increment field of B such as auto_increment_offset = 2 auto_increment_increment = 2 are: 2, 4, 6, 8 ,... You can see that your auto_increment field will never be repeated between 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.