Search code examples
mysqlauto-increment

MySql : autoincrement gets its original value when mysql server stops


I have a Mysql table autoincrement that is set to its initial value each time the mysql server is stopped.
I have read this is a normal behaviour for Mysql.

Is there a way to avoid this? Is it possible to set a value (max+1 from another table ) at mysql server start to set the autoincrement to "value + 1" it was just before the server stopped?

Thanks


Solution

  • http://dev.mysql.com/doc/refman/5.0/en/innodb-auto-increment-handling.html:

    ALTER TABLE table_name ENGINE=MyISAM;
    

    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