Skip to content

Latest commit

 

History

History
18 lines (14 loc) · 698 Bytes

File metadata and controls

18 lines (14 loc) · 698 Bytes
aliases author date tags title
/2007/07/01/repair-auto_increment-in-mysql/
Major Hayden
2007-07-01 09:34:03 -0700
database
emergency
Repair auto_increment in MySQL

Table corruption in MySQL can often wreak havoc on the auto_increment fields. I'm still unsure why it happens, but if you find a table tries to count from 0 after a table corruption, just find the highest key in the column and add 1 to it (in this example, I'll say the highest key is 9500).

Just run this one SQL statement on the table:

ALTER TABLE brokentablename AUTO_INCREMENT=9501;

If you run a quick insert and then run SELECT last_insert_id(), the correct key number should be returned (9501 in this case).