Home > database >  docker compose exec mysqldump prints sql instead of writing it
docker compose exec mysqldump prints sql instead of writing it

Time:09-21

I'm trying to run a mysqldump from inside the db service of my Docker Compose app.

Problem: Instead of dumping the file to /tmp/mydb.sql, it is printing the output to the screen.

Here is my command: docker compose exec db mysqldump -uroot mydb > /tmp/mydb.sql

There is no file in /tmp when this command is done running. I also confirmed that /tmp is writable.

How can I have the command write to /tmp/mydb.sql?

CodePudding user response:

Using the shell redirection can be tricky because by default, it is interpreted by the shell where you ran the docker command, not the shell inside the container.

If you want to ensure the output is redirected by the mysqldump command inside the container, I suggest you use mysqldump with the --result-file=/tmp/mydb.sql option (see the link for documentation) instead of getting confused with shell redirection.

  • Related