Knowledge Base

How to rename a MySQL database

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 A2 Hosting account includes cPanel access.

Managed accounts with cPanel

If your A2 Hosting account includes cPanel access, you can use cPanel to quickly and easily rename a MySQL database. To do this, follow these steps:

  1. Log in to cPanel.
    If you do not know how to log in to your cPanel account, please see this article.
  2. In the DATABASES section of the cPanel home screen, click MySQL® Databases:

    cPanel - Databases - MySQL Databases icon

    The MySQL® Databases page appears.

  3. Under Current Databases, locate the database you want to rename.
  4. In the Actions column, click Rename:

    cPanel - MySQL Databases - Rename

    The Rename Database dialog box appears.

  5. In the New name text box, type the new name for the database:

    cPanel - MySQL Databases - Rename Database dialog box

  6. Click Proceed. cPanel renames the database.
Semi-managed accounts without cPanel

If your A2 Hosting account does not include cPanel, you can rename a MySQL database manually from the command line. To do this, follow these steps:

  1. Log in to your server using SSH.
  2. 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"
  3. 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 -u username -p old_dbname > dbexport.sql
  4. 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
  5. 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"
    This step is optional. You do not have to delete the old database.
  6. You can now use the new database named new_dbname, which contains all of the tables and data from the old database.