Skip to content

Instantly share code, notes, and snippets.

@yarimadam
Created January 31, 2019 08:36
Show Gist options
  • Save yarimadam/70d6b41a4d152da333e094a1f2355d2b to your computer and use it in GitHub Desktop.
Save yarimadam/70d6b41a4d152da333e094a1f2355d2b to your computer and use it in GitHub Desktop.
Backup and restore a specific database from a running docker mysql container.

Step 1, dump database via mysqldump.

docker exec CONTAINER_NAME_OR_ID sh -c 'exec mysqldump --databases DATABASE_NAME -uUSER -pPASSWORD' > backup.sql

Step 2, import.

docker exec -i CONTAINER_NAME_OR_ID sh -c 'exec mysql -uUSER -pPASSWORD DATABASE_NAME' < backup.sql

Notice "-i" opiton in the import command. It allows to STDIN contents of the dumped sql file inside the container.

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