I had same issue; I tried with @variables and scripting successfully but finally the fastest way to me is:
1: add an "(int) value" column theintcolumn to the table yourtable
2: maybe you have to fill theintcolumn with zero values, if needed "update yourtable set theintcolumn=0;"
3: drop the primary key attribute of your previous primary key (thepreviouskey)
3: re-declare theintcolumn, now as primary key and autoincrement; it will fill automatically
4: you can do whatever you prefer up this point:
4:A: drop thepreviouskey column and rename theintcolumn to thepreviouskey ; then optimize yourtable. Fastest.
4:B: set thepreviouskey = theintcolumn; and then drop theintcolumn; but after that don't forget to re-assign primary key and autoincrement attributes to thepreviouskey column!