MySQL Renaming a MySQL table


Example

Renaming a table can be done in a single command:

RENAME TABLE `<old name>` TO `<new name>`;

The following syntax does exactly the same:

ALTER TABLE `<old name>` RENAME TO `<new name>`;

If renaming a temporary table, the ALTER TABLE version of the syntax must be used.

Steps:

  1. Replace <old name> and <new name> in the line above with the relevant values. Note: If the table is being moved to a different database, the dbname.tablename syntax can be used for <old name> and/or <new name>.
  2. Execute it on the relevant database in the MySQL command line or a client such as MySQL Workbench. Note: The user must have ALTER and DROP privileges on the old table and CREATE and INSERT on the new one.