In this tutorial, We will see how can we rename the existing table in Mysql, you can use the RENAME TABLE statement. This statement allows you to change the name of a table. Here's how you can do it:
Connect to the MySQL server: Open a command-line interface or a terminal and enter the following command, replacing <username> and <password> with your MySQL username and password:
Syntax:
mysql -u <username> -p
Once you are connected to the MySQL server, you will see a prompt where you can enter commands.
Rename the table:Use the RENAME TABLE statement followed by the current name of the table and the new name you want to assign to it. For example, to rename a table named "old_table" to "new_table", you can use the following command:
RENAME TABLE old_table TO new_table;
Verify the renaming:
You can use the SHOW TABLES; command to see a list of all tables in the current database. You should now see the table with its new name.
That's it! You have successfully renamed an existing table in MySQL.
Here's an example of the entire process:
In this example, the table named "old_table" was renamed to "new_table". The SHOW TABLES command confirms the table's new name.
Note: Ensure that you have the necessary privileges to rename a table. If you encounter any permission errors, you might need to use an account with appropriate privileges or contact your database administrator.