MySQL command rename 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 the name change is running, no other thread can be 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 swap two of table names, you have to:
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 perform 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 multiple table renaming, it will reverse the renaming of all renamed tables and return everything to its original state.
RENAME TABLE is added to the MySQL 3.23.23.