Learn how to take the backup of database and then restore it into new 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
b) Use UPGRADE DATA DIRECTORY command
You can use ALTER DATABASE db_name UPGRADE DATA DIRECTORY NAME as mentioned at http://dev.mysql.com/doc/refman/5.1/en/alter-database.html
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.