Skip to content

Instantly share code, notes, and snippets.

@amandiobm
Forked from spalladino/mysql-docker.sh
Created March 1, 2021 07:59
Show Gist options
  • Select an option

  • Save amandiobm/d9cd51e8c8c0068493144b3cbf928323 to your computer and use it in GitHub Desktop.

Select an option

Save amandiobm/d9cd51e8c8c0068493144b3cbf928323 to your computer and use it in GitHub Desktop.
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@amandiobm
Copy link
Author

For Windows using Powershell with a large database you should use

Backup

docker exec CONTAINER /usr/bin/mysqldump -u root --password=root -r DATABASE | Set-Content backup.sql

It will preserve encoding from the Linux container.

@amandiobm
Copy link
Author

docker exec some-mysql sh -c 'exec mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' > /some/path/on/your/host/all-databases.sql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment