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.
- Open the table
- Choose the "Structure" tab
- Click on "Move columns"
- Drag and drop column names
Solution 3:
If you are using MySQL workbench,
- Right-click on table
- Alter table
- drag columns and re-order
- 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;