Renaming a MySQL database
Learn how to rename a MySQL database with this complete walkthrough including detailed instructions, relevant code snippets, and links to related articles.
This article explains how to rename a MySQL database.
Renaming a MySQL database
You may need to rename a MySQL database from time to time, such as when you migrate data from one account or hosting provider to another, or during site development.
The steps to rename a MySQL database depend on whether or not your hosting.com account includes cPanel access.
Managed accounts with cPanel
If your hosting.com account includes cPanel access, you can use cPanel to quickly and easily rename a MySQL database. To do this, follow these steps:
-
Log in to cPanel.
Note
If you do not know how to log in to your cPanel account, please see this article.
-
On the Tools page, in the Databases section, click Manage My Databases:
Note
If you are using cPanel version 118 or earlier, click MySQL Databases instead:
-
Under Current Databases, locate the database you want to rename.
-
In the Actions column, click Rename:
The Rename Database dialog box appears.
-
In the New name text box, type the new name for the database:
-
Click Proceed. cPanel renames the database.
Unmanaged accounts without cPanel
If your hosting.com account does not include cPanel, you can rename a MySQL database manually from the command line. To do this, follow these steps:
-
Log in to your server using SSH.
-
At the command prompt, type the following command to create a new database. Replace username with the MySQL username, and replace new_dbname with the new database name that you want to use:
mysql -u username -p -e "CREATE DATABASE new_dbname"
-
To export the old database to a file, type the following command. Replace username with the MySQL username, and replace old_dbname with the name of the database that you want to rename:
mysqldump --routines -u username -p old_dbname > dbexport.sql
-
To import the data from the old database into the new database that you created in step 1, type the following command. Replace username with the MySQL username, and replace new_dbname with the name of the new database:
mysql -u username -p new_dbname < dbexport.sql
-
To delete the old database, type the following command. Replace username with the MySQL username, and replace old_dbname with the name of the database to delete:
mysql -u username -p -e "DROP DATABASE old_dbname"
Note
This step is optional. You do not have to delete the old database.
-
You can now use the new database named new_dbname, which contains all of the tables and data from the old database.
Related Articles
Updated 3 days ago