Copy/duplicate mysql database

When you need make a working copy of your database for example to use with copy of your wordpress site, you need to make few things:

# log into your mysql server
mysql -u root -p

# create new database that will store your original database copy
CREATE DATABASE db_copy;

quit;

Now that we have a db, let us dump the original db to file:

mysqldump -u root -p database_to_copy > db-copy.sql

This will dump database_to_copy database to file named db-copy.sql. Now we need to import this dump to our newly created database db_copy.

mysql -u root -p db_copy < db-copy.sql

Leave a Reply

Your email address will not be published.

*