# Renaming a MySQL database

> Rename a MySQL database in cPanel, or by exporting it, creating a new database and importing the data from the command line.

Source: https://helpcenter.ruachost.com/developers/databases/renaming-a-mysql-database/

**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 may be necessary during site development or when migrating data from one account or hosting provider to another. The method depends on whether your hosting account includes cPanel access.

**Managed Accounts with cPanel**\
If your account includes cPanel, you can rename a MySQL database easily:

1. Log in to cPanel.
2. In the Databases section, click **Manage My Databases** (or **MySQL Databases** in cPanel version 118 or earlier).       ![cPanel - Databases - Manage My Databases icon](https://helpcenter.ruachost.com/kb-images/0af69f37ef36.webp)
3. Under **Current Databases**, locate the database you want to rename.
4. In the **Actions** column, click **Rename**. ![cPanel - MySQL Databases - Rename](https://helpcenter.ruachost.com/kb-images/69420ee5cabc.webp)
5. In the **New name** text box, type the new database name. ![cPanel - MySQL Databases - Rename Database dialog box](https://helpcenter.ruachost.com/kb-images/8d92d03c0e8c.webp)
6. Click **Proceed**. cPanel renames the database.

**Unmanaged Accounts without cPanel**\
If your account does not include cPanel, you can rename a MySQL database from the command line:

1. Log in to your server using SSH.
2. Create a new database:

```
mysql -u username -p -e "CREATE DATABASE new_dbname"
```

3. Export the old database to a file:

```
mysqldump --routines -u username -p old_dbname > dbexport.sql
```

4. Import the data into the new database:

```
mysql -u username -p new_dbname < dbexport.sql
```

5. (Optional) Delete the old database:

```
mysql -u username -p -e "DROP DATABASE old_dbname"
```

You can now use the new database `new_dbname`, which contains all tables and data from the old database.
