Skip to content

Instantly share code, notes, and snippets.

@devdrops
Last active August 12, 2025 11:54
Show Gist options
  • Save devdrops/c59ee84504d128a7913a480b1191d66e to your computer and use it in GitHub Desktop.
Save devdrops/c59ee84504d128a7913a480b1191d66e to your computer and use it in GitHub Desktop.

Revisions

  1. devdrops revised this gist Dec 22, 2016. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions example.md
    Original 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'
    ```
  2. devdrops revised this gist Dec 22, 2016. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions example.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,11 @@
    # 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
    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:
  3. devdrops created this gist Dec 19, 2016.
    7 changes: 7 additions & 0 deletions example.md
    Original 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
    ```