September 14, 2020 - Patrick Kerwood

Dump SQL DB from a container

This is just two simple commands to backup and restore an active MySQL/MariaDB database running in a container.

So basically, below command just a mysqldump command, but it saves the dump file on the host instead of in the container. I use these commands maybe more often than I'd like to admit, when backing up a private hosted SQL database.

Again, I post these two commands because og my own deteriorating memory.

# Backup

docker exec -i [mysql_container_name] mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql

# Restore

docker exec -i [mysql_container_name] mysql -u root -p[root_password] [database_name] < dumpfilename.sql

Found a bug? Help me improve this page!
Last Commit: