How to change the column position of MySQL table without losing column data?

Solution 1:

Try this:

ALTER TABLE table_name MODIFY password varchar(20) AFTER id

Solution 2:

Hearaman's answer is correct; but if you are using phpMyAdmin, there is a visual and practical way to do that.

  1. Open the table
  2. Choose the "Structure" tab
  3. Click on "Move columns"
  4. Drag and drop column names

Move columns link, middle of the Structure tab Move columns popup

Solution 3:

If you are using MySQL workbench,

  1. Right-click on table
  2. Alter table
  3. drag columns and re-order
  4. click apply and finish

Solution 4:

Also, you can do it like this:

ALTER TABLE table_name CHANGE COLUMN column_name column_name data_type AFTER another_column_name;