How to reset the auto-increment of id AUTO_INCREMENT in MySQL?

created at 07-26-2021 views: 1

solution

ALTER TABLE tablename AUTO_INCREMENT = 1

Note: For InnoDB, you cannot set the auto_increment value to be less than or equal to the current maximum index.

Please note that you cannot reset the counter to any value less than or equal to the used value. For MyISAM, if the value is less than or equal to the current maximum value in the AUTO_INCREMENT column, the value will be reset to the current maximum value plus 1. For InnoDB, if the value is less than the current maximum value in the column, no error will occur, and the current sequence value will not change.

Please refer to How to Reset an MySQL AutoIncrement using a MAX value from another table? How to dynamically obtain acceptable values.

Please log in to leave a comment.