Last active
August 12, 2025 11:54
-
-
Save devdrops/c59ee84504d128a7913a480b1191d66e to your computer and use it in GitHub Desktop.
Revisions
-
devdrops revised this gist
Dec 22, 2016 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,3 +9,16 @@ docker exec -i mysql_container mysqldump -uroot -proot --databases database_name * This will generate a `dump.sql` file in your host machine. Awesome, eh? * Avoid using `--compact` on your dump. This will make MySQL check your constraints which will cause troubles when reading your file (damm you MySQL). And don't use `--force` to fix this scenario: recreate your dump without `--compact` ¯\_(ツ)_/¯ * You can execute the same command for both Docker and Docker Compose scenarios :wink: * To import again your dump in a MySQL container, the best approach is to have another container with your dump files added during the build process. In my experience, the usage of making Docker read the dump from your host right to the guest caused troubles (errors like `socket.error: [Errno 32] Broken pipe` and the terrific `ValueError: file descriptor cannot be a negative integer (-1)` described [here](https://github.com/docker/compose/issues/3352)). So, in order to import again your dump: * From Docker Compose: ```bash docker-compose exec mysql_service /bin/bash -c 'mysql -uroot -proot < /path/to/my/dump.sql' ``` * From Docker: ```bash docker exec mysql_container /bin/bash -c 'mysql -uroot -proot < /path/to/my/dump.sql' ``` -
devdrops revised this gist
Dec 22, 2016 . 1 changed file with 7 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,11 @@ # Mysqldump from Docker container ```bash docker exec -i mysql_container mysqldump -uroot -proot --databases database_name --skip-comments > /path/to/my/dump.sql ``` ## OBS * This will generate a `dump.sql` file in your host machine. Awesome, eh? * Avoid using `--compact` on your dump. This will make MySQL check your constraints which will cause troubles when reading your file (damm you MySQL). And don't use `--force` to fix this scenario: recreate your dump without `--compact` ¯\_(ツ)_/¯ * You can execute the same command for both Docker and Docker Compose scenarios :wink: -
devdrops created this gist
Dec 19, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ # Mysqldump from Docker container Generates `dump.sql` from a single database, in your host machine: ```bash docker exec -i mysql_container mysqldump -uroot -proot database_name > dump.sql ```