mysql将列id更改为从1开始并从那里自动增加

时间:2011-11-15 09:10:45

标签: mysql auto-increment

我在phpmyadmin中查看了我的表,注意到id从13410开始并增加1.我想重置并从一个开始。我读过许多人说最好不要理会它或者如果你弄乱它会变得复杂但是我仍然需要一个解决方案,至少在1开始id。 感谢

3 个答案:

答案 0 :(得分:10)

ALTER TABLE table AUTO_INCREMENT = 1

http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html

我希望你知道你做了什么!

答案 1 :(得分:8)

update *tablename* set id=id-13409;

然后找到最高ID:select id from tablename order by id desc limit 1;

然后重置auto_increment:alter table tablename auto_increment=12345;(将12345更改为最高ID加1)

答案 2 :(得分:1)

You can reset the auto increment to desired value using the following statement , 
eg : mysql> ALTER TABLE tbl AUTO_INCREMENT = 100;