How to rearrange MySQL columns?

Solution 1:

Modify also works. Have a look:

ALTER TABLE foo MODIFY bar bartype AFTER baz;

Solution 2:

The only way I know is to change the column. You would first extract your column definition using SHOW CREATE TABLE and issue an ALTER TABLE:

ALTER TABLE foo
CHANGE COLUMN bar
bar COLUMN_DEFINITION_HERE
FIRST;

Or if you want it after a certain other column:

... AFTER OTHER_COLUMN;

Solution 3:

  1. Alter Table table_name modify column_name column_datatype first;
  2. Alter Table table_name modify column_name column_datatype After other_column_name;