Running SQL scripts in a docker container

I have a docker container running mysql and I want to insert the .sql file into the container and then mysql execute the commands in it. The first step is pretty simple:

docker cp ./dummy.sql <container_id>:/

From there I try to start mysql from the command line and point it to a file that I just clicked into the container.

docker exec <container_id> mysql -u root -ppassword < /dummy.sql

This command tries to use /sample.sql as stdin locally, and not in the container. I also tried wrapping quotes around everything after the container identifier, which also does not seem to work.

I also tried pushing the .sh file using the command in it into the docker container, and then just executing it, but it is less perfect and also does not work. Any tips?

+4
source share
2

, /bin/sh:

docker exec <container_id> /bin/sh -c 'mysql -u root -ppassword </dummy.sql'
+6

Try:

docker exec <container_id> 'mysql -u root -ppassword </dummy.sql'
+1

Source: https://habr.com/ru/post/1624198/


All Articles