想将表中的数据清空重新添加数据时,希望id重新从1开始计数,用以下两种方法均可:
alter table tablename drop column id;
alter table tablename add id mediumint(8) not null primary key auto_increment first;
方法二:
1 | alter table tablename auto_increment=0 |
方法二不会清空已有数据,操作比较灵活,不仅可以将自增值归零,也适用于删除大量连续行后,重新设置自增值并插入新的数据;或从新的值开始,当然不能和已有的冲突。