Wednesday, July 27, 2011

MySQL: Copy / clone database in MySQL

I needed to create a exact replica of my existing MySQL Magento database so that I could use it for my development.

A elegant solution was

mysqldump -u SRC_DB_USER --password=SRC_DB_PASSWORD -h SRC_DB_HOST SRC_DB_NAME | mysql -u DST_DB_USER --password=DST_DB_PASSWORD -h DST_DB_HOST DST_DB_NAME


where
- SRC_DB_* is the source database
- DST_DB+* is the destination Database

If you wanted to create a datavase also, you could have used

mysqladmin create  -u DST_DB_USER --password=DST_DB_PASSWORD -h DST_DB_HOST DST_DB_NAME && \
mysqldump -u SRC_DB_USER --password=SRC_DB_PASSWORD -h SRC_DB_HOST SRC_DB_NAME \
| mysql -u DST_DB_USER --password=DST_DB_PASSWORD -h DST_DB_HOST DST_DB_NAME




No comments:

Post a Comment