Dump and restore a MariaDB database

Backups, moving a database to another server, or copying production to your machine.

SNP 033 #953 Filed sql mariadb cmd

Dump:

shell
mysqldump -u root -p --single-transaction --routines shop > shop.sql

--single-transaction makes a consistent dump of InnoDB tables without locking them. Compress it if it's big:

shell
mysqldump -u root -p --single-transaction shop | gzip > shop.sql.gz

Restore into an existing (empty) database:

shell
mysql -u root -p shop < shop.sql
gunzip < shop.sql.gz | mysql -u root -p shop

On MariaDB the commands are also available as mariadb-dump and mariadb; the mysql names are compatibility aliases.