Changing auto_increment on MySQL

From time to time, when programming with MySQL, I have needed to change the auto_increment value to something other than the default (Typically it starts counting with 1 and goes up from there). To change this, simply use the following command:

mysql> ALTER tablename AUTO_INCREMENT=new_number

There you go, it is that easy to change the auto increment value for MySQL.

NOTE: I have discovered that MySQL will not allow you to set the auto_increment value to a number smaller that what is currently set. The data must be truncated and then set to get it to work properly.

Leave a Reply

Switch to our mobile site