BACKUP/RESTORE TABLE lose auto increment

One small fact about backup table and restore table that isn’t listed in the manual is that these commands lose the auto increment value if rows at the head of the table are deleted. For example if you have auto increment values of 1,2,3,4 in a table the auto increment value is 5. If you delete row 4 the next auto increment will still be 5. If you backup/restore the table the auto increment will be reset to 4. The auto increment value in myisam is stored in the MYI file. Since this file isn’t backed up myisam restores the auto increment value from the highest existing value in the table. This value may or may not be the actual value of auto increment. As the manual says these commands should not be used. Instead use mysqlhotcopy.

2 Comments

  1. chris says:

    mysqlhotcopy sounds good but since my health care organization mainly use innodb tables we can’t use it.

  2. Can you provide some more details on this?

Leave a Reply