/ mozey.co / blog

mysql backup

July 1, 2013

This command can be used to backup a MySQL database

mysqldump --user myUserName --password=myPassword myDatabaseName > myDatabaseName.sql

The backup file can also be gzipped

mysqldump --user myUserName --password=myPassword myDatabaseName | gzip -c | cat > myDatabaseName.sql.gz

To unzip the backup use

gunzip myDatabaseName.sql.gz

Restoring the backup

mysql -u myUserName -p  myDatabaseName < myDatabaseName.sql

Or restoring from the cli client

drop database myDatabaseName; create database myDatabaseName; use myDatabaseName; source myDatabaseName.sql;