How to rename a MySQL database - Rocketeers

 On this page

 Knowledge
---------

How to rename a MySQL database
==============================

### [\#Databases](http://rocketee.rs/index.php/databases)

Unlike renaming a table, you can't rename a database in MySQL sadly enough. So there is no SQL query you can execute to achieve this. However, it is possible with a workaround.

 Published by Mark van Eijk on September 24, 2024 
Updated on September 25, 2024 · 1 minute read

1. [Create a newly named database](#content-create-a-newly-named-database)
2. [Dump &amp; import](#content-dump--import)
3. [Drop the old database](#content-drop-the-old-database)

The most important step: To get going with this, first [create a full backup of your MySQL database](/backup-mysql-databases-single-file) to make sure you don't loose any data!

[\#](#content-create-a-newly-named-database "Permalink")Create a newly named database
-------------------------------------------------------------------------------------

This step involves creating the database you want to rename the old database to:

 ```
CREATE DATABASE `NEW_DATABASE_NAME`;

```

[\#](#content-dump--import "Permalink")Dump &amp; import
--------------------------------------------------------

Dump and import the old database into your new database:

 ```
mysqldump -u USERNAME -p OLD_DATABASE_NAME | mysql -u USERNAME -p NEW_DATABASE_NAME

```

[\#](#content-drop-the-old-database "Permalink")Drop the old database
---------------------------------------------------------------------

If your really sure, you can (with the backup on hand) remove the old database safely:

 ```
DROP DATABASE `OLD_DATABASE_NAME`

```

### Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

  Fill in your email address to receive updates  Subscribe 

#### Related articles

[Stream MySQL backup directly to S3 bucket](http://rocketee.rs/index.php/stream-mysql-backup-s3-bucket)
-------------------------------------------------------------------------------------------------------

Unlike renaming a table, you can't rename a database in MySQL sadly enough. So there is no SQL query you can execute to achieve this. However, it is possible with a workaround.

[Read more →](http://rocketee.rs/index.php/stream-mysql-backup-s3-bucket)

[Export MySQL database using command line](http://rocketee.rs/index.php/export-database-mysql-command-line)
-----------------------------------------------------------------------------------------------------------

Unlike renaming a table, you can't rename a database in MySQL sadly enough. So there is no SQL query you can execute to achieve this. However, it is possible with a workaround.

[Read more →](http://rocketee.rs/index.php/export-database-mysql-command-line)
