Reputation: 3525
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?
Upvotes: 5
Views: 2408
Reputation: 310
ALTER TABLE table_name ENGINE=MyISAM
Works for me. InnoDB stores the AI in memory, so it's reset to current number of rows + 1 when mysql server is restarted. So if your table is empty when you restart the server, it will be reset to 1.
MyISAM on the other hand was well built.
Upvotes: -1
Reputation: 367
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.
Upvotes: 3