Share on Google+Share on Google+

In this section you will learn how to rename MySQL database.

Learn how to take the backup of database and then restore it into new database.

How to rename MySQL database?

In this section we will learn the safest method to rename MySQL Database.

The following statement was added in the MySQL version 5.1.7:

RENAME {DATABASE | SCHEMA} db_name TO new_db_name;

But it was removed in the MySQL 5.1.23 as it was dangerous command and it may lead data loss.

Here are the best option to rename the database:

a) Take dump and restore into new database

Take the backup of database using mysqldump utility as mentioned below:

Use the following command to backup accounts database into accounts.sql:
mysqldump -u root -p root accounts > accounts.sql

and then create new database using following command

create database account2;

and then restore the data into accounts2 database using following command:

mysql - u root -p root accounts < accounts2.sql


You can use ALTER DATABASE db_name UPGRADE DATA DIRECTORY NAME as mentioned at

The database data is important organizations assets it must be handled correctly. You must be very careful while renaming the database. Before renaming the database take the backup of the database.


Posted on: July 12, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null