Easy Backup & Restore a MySQL Database

If you want to make a database backup, it’s better to not use phpMyAdmin, because larger databases will cause that method of backup to fail. Instead, just use mysqldump, which should already be installed if mysql is installed:

#backup 
mysqldump -u username -ppassword database | gzip > ./dumpfilename.sql.gz

#restore
gunzip < ./dumpfilename.sql.gz | mysql -u username -ppassword database

If you need to do a search and replace of a domain name, because you are pulling in a production dump to use on a development machine, do this:

#restore with domain search and replace
gunzip < "./dumpfilename.sql.gz" | sed "s/production.com/dev.com/g" |  mysql -u username -ppassword database

One thought on “Easy Backup & Restore a MySQL Database”

Comments are closed.