Home » MySQL

Reset MySQL auto increment to 1

11 December 2008 No Comment

Here’s a quick reference to reset the MySQL auto_increment field to 1 and delete ALL rows in a table. This is useful in case you had to do some testing and wanted to reset the primary key field back to 1 and clear out the table.

truncate table [NAME OF TABLE]

If you don’t want to wipe out the table, you can reset the auto_increment by using:

alter table [NAME OF TABLE] auto_increment=1

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.