Wednesday, January 13, 2010

Backup and restore mysql database using mysqldump gzip and scp

First create a dump of the database where faqs is the name of the database
mysqldump -u root -h localhost -pmypassword faqs | gzip -9 > faqs-db.sql.gz

This will create a gzipped file containing insert statements

To transfer the file to another computer
scp faqs-db.sql.gz root@my.other.host.com:/home/username/faqs-db.sql.gz

Create the database on the new sql you want to import to
mysql -uroot -p
create faqs;
exit

To import the file into a new mysql database named faqs
gunzip -c faqs-db.sql.gz | mysql -uroot -pmypassword faqs

No comments:

Post a Comment