How to rename a mysql database

There isn’t a simple command to rename a mysql database. You just need to create a new database and then rename all the tables like so:

RENAME TABLE old_db.table_name TO new_db.table_name

There is also an alternative method by dumping the old database and importing it again like so:

mysqldump -v oldDatabase > oldDump.sql
mysqladmin create newDatabase
mysql newDatabase < oldDump.sql

I have found the second option to be alot faster both in time and on the disk.

Leave a Reply