一般情况下自增id都是有关联其它表的,这样强行恢复连续自增的话是灾难;
1 删除自增字段,然后重建ID:
ALTER TABLE `tablename` DROP COLUMN `id`;
TABLE `tablename` ADD `id` int(10) unsigned NOT NULL AUTO_INCREMENT FIRST,ADD PRIMARY KEY (`id`), AUTO_INCREMENT = 0 ROW_FORMAT = COMPACT;
2 通过 SQL 语句按顺序重置自增字段值:
SET @i=0;
UPDATE `tablename` SET `id`=(@i:=@i+1);
ALTER TABLE `tablename` AUTO_INCREMENT=0;