Reset the auto increment value for a MySQL table
Posted June 28th, 2008 in MySql
It is possible to reset the auto increment value of a MySQL auto incremental primary key to a new value, either higher or lower than what it would otherwise next be. This post looks at how to do this using a MySQL query and also with phpMyAdmin.
The following example changes the auto increment value for the table named "mytable" to 500. This means that the next time you insert a record into this table the value of the auto incremental primary key will be 500. If the highest value for the column is already greater than 500 then it will be set to the highest value plus 1.
ALTER TABLE mytable AUTO_INCREMENT = 500
The next example shows doing the same thing in phpMyAdmin. Select the database then table, and click the "Operations" tab. The current next auto increment value is already displayed - to change it enter a new value and then click the "Go" button. The relevent buttons etc are highlighted with red circles in the screenshot below.

In the above example, the current auto increment value is 39, meaning that when the next record is inserted the primary key will be 39. You can attempt change it to a lower number, e.g. 20, but if the highest value for the primary key is higher than 20 (e.g. 23) then it will instead be changed to the current highest plus 1 (e.g. if the highest value was 23 then it will be set to 24 instead of 20).
Related posts:
- How to enable remote access to a MySQL database server (Wednesday, April 1st 2009)
Share or Bookmark
Share or Bookmark this page using the following services. You will need to have an account with the selected service in order to post links or bookmark this page.
Subscribe or Follow
Subscribe via RSS or email, or follow me on Facebook or Twitter below. The RSS icon takes you through to Feedburner where you can select the service or application to use.

