If the table was empty, you could simply do:
ALTER TABLE mytable MODIFY COLUMN id bigint not null primary key auto_increment
but I'm not sure what will happen to the lines in it. It’s best to create a new one with the correct definitions, copy the data minus the id column, delete the old (wrong) table and transfer the new one to the old name.
-- Either: CREATE TABLE newtable LIKE mytable; ALTER TABLE newtable MODIFY COLUMN id bigint not null primary key auto_increment; -- or: CREATE TABLE newtable ( id bigint not null primary key auto_increment, column1 type1, column2 type2, ... ); INSERT INTO newtable (column1, column2, ...) SELECT column1, column2, column3, ... FROM mytable; -- Make SURE that insert worked BEFORE you drop the old table -- and lose data if it didn't. DROP TABLE mytable; ALTER TABLE newtable RENAME TO mytable;
I am sure phpMyAdmin has the ability to do this more graphically.
Kevin source share