Renaming a MySQL Database

Option-1 To reduce IO use the following.

mysqladmin -u username -p create newdatabase
mysqldump -u username -v olddatabase -p | mysql -u username -p -D newdatabase
Option-2 Renaming a MySQL Database:

In Linux shell, use mysqldump to back up the old database, then restore the dumped database under a new name using the MySQL utility.
Finally, use the drop database command to drop the old database. This option can perform badly for large database.
mysqldump -u root -p newdb > newdb.sql
mysql -uroot -p -e “CREATE DATABASE newdb1”
mysql -uroot -p newdb1 < newdb.sql
mysql -uroot -p -e “DROP DATABASE newdb”
Option-3 Use these few simple commands

mysqldump -u username -p -v olddatabase > olddbdump.sql
mysqladmin -u username -p create newdatabase
mysql -u username -p newdatabase < olddbdump.sql

Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: