Skip to content

Instantly share code, notes, and snippets.

@theredhead
Created December 1, 2020 09:05
Show Gist options
  • Save theredhead/58a602afecd1aaa294fba46b87db3c11 to your computer and use it in GitHub Desktop.
Save theredhead/58a602afecd1aaa294fba46b87db3c11 to your computer and use it in GitHub Desktop.
Backup and restore mysql databases running in docker containers (from docker host shell)
# CONTAINER_ID => value of container id column from `docker ps`
# DATABASE_NAME => name of the mysql database to backup/restore
# Backup to backup-file.sql outside container
docker exec CONTAINER_ID /usr/bin/mysqldump --triggers --routines -uMYSQL_USER -pMYSQL_PASSWORD DATABASE_NAME > backup-file.sql
# Restore from backup-file.sql outside container
cat backup-file.sql | docker exec -i CONTAINER_ID /usr/bin/mysql -uMYSQL_USER -pMYSQL_PASSWORD DATABASE_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment