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 Webhost.Berlin account includes cPanel access.

Managed accounts with cPanel

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

  1. Log in to cPanel.
  2. In the Databases section of the cPanel home screen, click phpMyAdmin. The phpMyAdmin administration page appears in a new window.
  3. In the left pane of phpMyAdmin, click the name of the database you want to rename.
  4. On the top menu bar, click Operations.
  5. Under Rename database to, type the new name for the database, and then click Go.
  6. To confirm the renaming of the database, click
    . phpMyAdmin renames the database and reloads it.
  7. The newly renamed database does not have any users assigned to it yet, so in the Databases section of the cPanel home screen, click MySQL Databases.
  8. Add a user to the new database and assign the user permissions that you want.
    For information about how to manage MySQL users and permissions in cPanel, please see this article.
Semi-managed accounts without cPanel

If your Webhost.Berlin 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.