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_INCREMENTcolumn is not replicated correctly using statement-based replication. These statements are marked as unsafe. (Bug #45677)
- An - INSERTinto a table that has a composite primary key that includes an- AUTO_INCREMENTcolumn 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 - InnoDBstorage engine, since an- InnoDBtable with an AUTO_INCREMENT column requires at least one key where the auto-increment column is the only or leftmost column.
- Adding an - AUTO_INCREMENTcolumn to a table with- ALTER TABLEmight not produce the same ordering of the rows on the replica and the source. 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 source and replica, the rows must be ordered before assigning an- AUTO_INCREMENTnumber. Assuming that you want to add an- AUTO_INCREMENTcolumn to a table- t1that has columns- col1and- col2, the following statements produce a new table- t2identical to- t1but with an- AUTO_INCREMENTcolumn:- CREATE TABLE t2 LIKE t1; ALTER TABLE t2 ADD id INT AUTO_INCREMENT PRIMARY KEY; INSERT INTO t2 SELECT * FROM t1 ORDER BY col1, col2;Important- To guarantee the same ordering on both source and replica, the - ORDER BYclause must name all columns of- t1.- The instructions just given are subject to the limitations of - CREATE TABLE ... LIKE: Foreign key definitions are ignored, as are the- DATA DIRECTORYand- INDEX DIRECTORYtable options. If a table definition includes any of those characteristics, create- t2using a- CREATE TABLEstatement that is identical to the one used to create- t1, but with the addition of the- AUTO_INCREMENTcolumn.- Regardless of the method used to create and populate the copy having the - AUTO_INCREMENTcolumn, the final step is to drop the original table and then rename the copy:- DROP t1; ALTER TABLE t2 RENAME t1;