Renaming a table keeps schemas readable, supports clearer naming conventions, and enables safe cutovers when swapping in a rebuilt table or archiving old data.
In MySQL and MariaDB, table renames are performed with RENAME TABLE, which changes the table name in the database metadata without copying table data. The same statement can rename multiple tables at once, which is useful for atomic swaps during deployments.
Renames still require metadata locks, so active transactions can delay completion and cause application-side stalls when the rename waits. Case sensitivity and filesystem behavior can also affect renames that only change letter case, and any stored SQL text (views, routines, app queries) may need updates if it references the old name.
$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 48 Server version: 8.0.44 MySQL Community Server - GPL Copyright (c) 2000, 2025, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
mysql> USE table_demo; Database changed
mysql> SHOW FULL TABLES LIKE 'rename_demo'; +------------------------------------+------------+ | Tables_in_table_demo (rename_demo) | Table_type | +------------------------------------+------------+ | rename_demo | BASE TABLE | +------------------------------------+------------+ 1 row in set (0.00 sec)
mysql> SHOW FULL TABLES LIKE 'rename_demo_archive'; Empty set (0.00 sec)
mysql> RENAME TABLE rename_demo TO rename_demo_archive; Query OK, 0 rows affected (0.00 sec)
The statement waits for a metadata lock; long-running queries or transactions can make the rename block and hold up DDL in busy schemas.
Atomic swap for cutovers: RENAME TABLE orders TO orders_old, orders_new TO orders; changes both names in one statement.
Case-only renames can be tricky on case-insensitive filesystems or when lower_case_table_names is enabled; use an intermediate name (tmp) if a case-only rename does not take effect.
mysql> SHOW TABLES LIKE 'rename_demo_archive'; +--------------------------------------------+ | Tables_in_table_demo (rename_demo_archive) | +--------------------------------------------+ | rename_demo_archive | +--------------------------------------------+ 1 row in set (0.00 sec)
mysql> DESCRIBE rename_demo; ERROR 1146 (42S02): Table 'table_demo.rename_demo' doesn't exist
Views, procedures, functions, and application queries are text-based and are not automatically rewritten by a table rename.
Example: RENAME TABLE `order` TO `order_archive`;
mysql> RENAME TABLE table_demo.rename_demo_archive TO archive_db.rename_demo_archive; Query OK, 0 rows affected (0.00 sec)
Cross-database renames remain metadata operations, but privileges and table-level grants may need review when access is scoped to a specific database or table name.