MySQL command renaming tables rename table syntax
RENAME TABLE tbl_name to new_tbl_name[, tbl_name2 to
New_tbl_name2,...]
Renaming is performed atomically (atomically), which means that when renaming is running, no other thread will be able to make the table. This makes it possible to replace a table with an empty table.
CREATE TABLE new_table (...);
RENAME TABLE old_table to Backup_table, new_table to old_table;
Renaming is performed from left to right, which means that if you want to exchange two table names, you have to do this:
RENAME TABLE old_table to Backup_table,
New_table to Old_table,
Backup_table to New_table;
As long as two databases are on the same disk, you can also rename from one database to another:
RENAME TABLE current_db.tbl_name to Other_db.tbl_name;
When you execute RENAME, you cannot have any locked tables or active transactions. You must also have ALTER and DROP permissions on the original table, as well as CREATE and INSERT permissions on the new table.
If MySQL encounters any errors in the multi-table renaming, it reverses all renamed tables, returning everything to its original state.
RENAME TABLE was added to MySQL 3.23.23.
MySQL command renaming tables rename table syntax