Strange questions about auto_increment in MySQL master-slave Replication

Source: Internet
Author: User
When I modified a table field yesterday, I found that the master-slave replication synchronization failed, but the synchronization process was not faulty, and the MySQL Log was not faulty. I carefully searched for the cause, it is found that the starting values of the newly added auto-incrementing primary key fields are inconsistent with those in the master/Slave database. As a result, the corresponding records cannot be found in the slave database when data is updated by the primary key. The procedure is as follows:

Table 1 (the master database is of the InnoDB type, and the slave database is of the MyISAM type) has an auto-incrementing primary key PID. Now, the PID is changed to non-auto-incrementing and non-primary key, and an auto-incrementing primary key is added.

Alter table Table1 modify PID int not null;

Alter talbe Table1 drop primary key;

Alter table Table1 add aid int not null auto_increment primary key first;

As a result, the auto_increment attribute of Table 1 in the master database is automatically unavailable. The value starts from 1 by default. However, the auto_increment attribute of Table 1 in the master database is still the maximum value of the previous PID.

The strange thing is that I have changed the slave database to InnoDB. I suspect it is a MySQL bug. Record it here and pay attention to it later.

Related Article

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.