Rechercher dans le manuel MySQL
17.4.1.1 Replication and AUTO_INCREMENT
Statement-based replication of
AUTO_INCREMENT
,
LAST_INSERT_ID()
, and
TIMESTAMP
values is carried out
subject to the following exceptions:
A statement invoking a trigger or function that causes an update to an
AUTO_INCREMENT
column is not replicated correctly using statement-based replication. These statements are marked as unsafe. (Bug #45677)An
INSERT
into a table that has a composite primary key that includes anAUTO_INCREMENT
column that is not the first column of this composite key is not safe for statement-based logging or replication. These statements are marked as unsafe. (Bug #11754117, Bug #45670)This issue does not affect tables using the
InnoDB
storage engine, since anInnoDB
table with an AUTO_INCREMENT column requires at least one key where the auto-increment column is the only or leftmost column.Adding an
AUTO_INCREMENT
column to a table withALTER TABLE
might not produce the same ordering of the rows on the slave and the master. This occurs because the order in which the rows are numbered depends on the specific storage engine used for the table and the order in which the rows were inserted. If it is important to have the same order on the master and slave, the rows must be ordered before assigning anAUTO_INCREMENT
number. Assuming that you want to add anAUTO_INCREMENT
column to a tablet1
that has columnscol1
andcol2
, the following statements produce a new tablet2
identical tot1
but with anAUTO_INCREMENT
column:ImportantTo guarantee the same ordering on both master and slave, the
ORDER BY
clause must name all columns oft1
.The instructions just given are subject to the limitations of
CREATE TABLE ... LIKE
: Foreign key definitions are ignored, as are theDATA DIRECTORY
andINDEX DIRECTORY
table options. If a table definition includes any of those characteristics, createt2
using aCREATE TABLE
statement that is identical to the one used to createt1
, but with the addition of theAUTO_INCREMENT
column.Regardless of the method used to create and populate the copy having the
AUTO_INCREMENT
column, the final step is to drop the original table and then rename the copy:
Document created the 26/06/2006, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/mysql-rf-replication-features-auto-increment.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.