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




SVN help: Easy way to delete .svn folders

If you need to delete .svn in folders, here is a simple Linux command
rm -rf `find . -name .svn`

This can come very useful if you have made a copy/backup of the folder.
Another use is if the folder is copied from one project to another project. In which case, you will not be able to add the folder into SVN as it will tell you that this directory already exist under svn. It is best if you delete all the .svn and then do a 'svn add'