Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto increment get reset to 0 at every service restart

It worked until now but when i restart the service, the database lost the auto-increment value for my table. It's for sure something i do with my queries, because i didn't modified my tables recently. What could it be?

like image 306
Chobeat Avatar asked Nov 05 '22 11:11

Chobeat


1 Answers

That is the documented behaviour, it's not a bug.
When the server starts up, it goes through each (InnoDB) table determining what the new auto_increment value should be. From http://dev.mysql.com/doc/refman/5.0/en/innodb-auto-increment-handling.html :

InnoDB uses the in-memory auto-increment counter as long as the server runs. When the server is stopped and restarted, InnoDB reinitializes the counter for each table for the first INSERT to the table, as described earlier.

It does something similar when you deploy DDL that causes a table rebuild, such as altering the engine -- even altering it to the same value it was before.

like image 187
niczero Avatar answered Nov 11 '22 15:11

niczero