Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
Copy link

blu-IT commented Jul 19, 2022

Since you take a mysql dump, automatically the .sql file will appear in your host folder. Tell me what you think?


Thanks! I already solved its (inside my script) this way:

docker cp <container_id>:/file/path/within/container /host/path/target

Copy link

behai-nguyen commented Aug 7, 2022

Very sweet. Thank you very much.

Copy link

echanobe commented Aug 14, 2022

Thank you!

Copy link

Tipset commented Aug 17, 2022

This helped a bunch, thank you!

Copy link

hkanizawa commented Aug 24, 2022


Copy link

tomaszroot commented Aug 31, 2022


Copy link

botosdavid commented Sep 19, 2022

thank you so much!

Copy link

dorimusz commented Sep 19, 2022

Thanks a lot!

Copy link

ttcosta11 commented Sep 26, 2022

Thank you!

Copy link

tgiovanella87 commented Oct 12, 2022

Great! Thanks!

Copy link

paulovnas commented Nov 4, 2022

Very nice... Thank you so much.

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