Rename a database in MySQL

Rename a database in MySQL

 1 : take backup of the database to be renamed

mysqldump -u root -p -R school_dev > school_dev.sql

 2 :  in the backup file Replace <UserName> and <Password> with the actual credentials for the database, and replace <DB_Name>  with the exact name of the database you’re changing. There should be no space between -p and the password. 

The -R flag indicates that the dump file should retain all stored procedures and functions.

 3. Create a new blank database by using the mysqladmin command:

mysqladmin -u root -p create school_dev_rp

Enter password: *********

 4 . Import the dump file into the new database you created:

mysql -u root -p school_dev_rp < school_dev_rp.sql

Enter password: *********


5  : Delete the old MySQL database name (optional):

mysqladmin -u root -p drop school_dev

Enter password: *********

Dropping the database is potentially a very bad thing to do.

Any data stored in the database will be destroyed.


Do you really want to drop the 'school_dev' database [y/N] y

Database "school_dev" dropped


Post a Comment

And that's all there is to it!

If anyone has any other questions or requests for future How To posts, you can either ask them in the comments or email me. Please don't feel shy at all!

I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.

Previous Post Next Post