Before you begin

In this tutorial will learn how to backup a MySQL database. A Linux machine and Docker will be required to follow this tutorial.

Backup a MySQL local or remote database

Command to backup a local or remote MySQL database using Docker:

$ docker run -it mysql /usr/bin/mysqldump -h [MYSQL_HOST] -u [MYSQL_USER] --password=[MYSQL_PASSWORD] [MYSQL_DATABASE] > backup.sql

Command to backup a local or remote MySQL database using Docker with compression (using gzip):

$ docker run -it mysql /usr/bin/mysqldump -h [MYSQL_HOST] -u [MYSQL_USER] --password=[MYSQL_PASSWORD] [MYSQL_DATABASE] | gzip -9 > backup.sql.gz

Backup a containerized MySQL database

Command to backup a containerized MySQL database creating a compressed file using Docker and gzip:

$ docker exec [MYSQL_CONTAINER] /usr/bin/mysqldump -u [MYSQL_USER] --password=[MYSQL_PASSWORD] [MYSQL_DATABASE] | gzip -9 > backup.sql.gz