January 3, 2017

MySQL – Backup and Restore

Backup

# Backup a database
$ mysqldump --user=name --password database > filename.sql

# Backup a database and gzip
$ mysqldump --user=name --password database | gzip > filename.sql.gz

Restore

# Restore a database
$ mysql --default-character-set=latin1 --user=name --password database < filename.sql

# Restore a database from gzip
$ gunzip -c filename.sql.gz | mysql --default-character-set=latin1 --user=name --password database 

No comments: