You can reset the counter with:
(您可以使用以下方法重置计数器:)
ALTER TABLE tablename AUTO_INCREMENT = 1
For InnoDB you cannot set the auto_increment
value lower or equal to the highest current index.
(对于InnoDB,您不能将auto_increment
值设置为auto_increment
或等于当前最大索引。)
(quote from ViralPatel ): ((引自ViralPatel ):)
Note that you cannot reset the counter to a value less than or equal to any that have already been used.
(请注意,您不能将计数器重置为小于或等于已使用的值。)
For MyISAM, if the value is less than or equal to the maximum value currently in the AUTO_INCREMENT column, the value is reset to the current maximum plus one. (对于MyISAM,如果该值小于或等于AUTO_INCREMENT列中当前的最大值,则该值将重置为当前的最大值加1。)
For InnoDB, if the value is less than the current maximum value in the column, no error occurs and the current sequence value is not changed. (对于InnoDB,如果该值小于该列中的当前最大值,则不会发生错误,并且当前序列值不会更改。)
See How to Reset an MySQL AutoIncrement using a MAX value from another table?
(请参见如何使用另一个表中的MAX值重置MySQL自动增量?)
on how to dynamically get an acceptable value. (如何动态获得可接受的值。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…