MySQL Renaming a column in a MySQL table


Example

Renaming a column can be done in a single statement but as well as the new name, the "column definition" (i.e. its data type and other optional properties such as nullability, auto incrementing etc.) must also be specified.

ALTER TABLE `<table name>` CHANGE `<old name>` `<new name>` <column definition>;

Steps:

  1. Open the MySQL command line or a client such as MySQL Workbench.
  2. Run the following statement: SHOW CREATE TABLE <table name>; (replacing <table name> with the relevant value).
  3. Make a note of the entire column definition for the column to be renamed (i.e. everything that appears after the name of the column but before the comma separating it from the next column name).
  4. Replace <old name>, <new name> and <column definition> in the line above with the relevant values and then execute it.