How to rename a table in MySQL

In this article, we will see how to rename a table in MySQL. We use alter command to change the table in MySQL. To rename table in MySQL, we must be owner of table or alter privilege on table.

Syntax to change table name in MySQL:

ALTER TABLE table_name RENAME TO new_tabl_name;

Examples:

1. Rename a table named ’emp’ to ’employee’.

Get the list of tables.

mysql> show tables; +---------------------+ | Tables_in_r2schools | +---------------------+ | dept | | emp | | student | | test1 | +---------------------+ 4 rows in set (0.00 sec)

Rename table emp.

alter table emp rename to employee;

How to rename a table name in MySQL

After rename lets verify the tables.

mysql> show tables; +---------------------+ | Tables_in_r2schools | +---------------------+ | dept | | employee | | student | | test1 | +---------------------+ 4 rows in set (0.00 sec)

So, we have successfully renamed table in MySQL.