fbpx

reset auto_increment mysql

April 6, 2008

In certain versions of MySQL, truncate does NOT reset the auto_increment value to 0! Instead, it is mapped to DELETE. Make sure you consider this when designing your database, as the current manual does not seem to address this issue.
More information can be found here: http://bugs.mysql.com/11946
The above URL states that the bug is limited to unpatched versions 5.0.xx prior to version 5.0.3. However, I have noticed the same behavior in version 4.1.21.

That being said, here’s a very simple way to get around this problem without having to look for a patch and whatnot. After you use truncate to delete the contents of the table, you can use the alter table command to reset the auto increment manually. With that in mind, try this on the
table you want to clear:

truncate table_name;
alter table table_name auto_increment=1;

avatar
Gonzalo Escribano

Ver entradas

Most Recent

June 9, 2022

¿Qué son las DAO y cuáles son sus beneficios?

Es común en la historia contemporánea que haya cambios a partir de los avances en el campo de la...

Read More

June 2, 2022

¿Qué son las DeFi y por qué son el futuro de las finanzas?

Es común en la historia contemporánea que haya cambios a partir de los avances en el campo de la...

Read More

May 27, 2022

How to start a successful product build from scratch?

Creating a product from scratch could be a huge challenge. To achieve your business goals it’s important to develop...

Read More