How to force a dump import with docker exec?

Vinícius :

I'm trying to import a database to my mysql container in Docker but I had some errors with sql file.

I used this code to import the data:

docker exec -i MYCONTAINER mysql -uMYUSER -pMYPASS@ -f -D MYDATABASE < MYFILE.sql

But still returns a error about syntax from file, I can't open this file cause is too huge, the only way to do this is with mysqldump. Anybody else have a method to import this file?

Thanks in advance!

Nguyen Lam Phuc :

When you run the command docker exec <container_name> <command>, the command will be executed inside the container and since the MYFILE.sql does not exist inside that container, it will definitely throw errors.

Another problem is that the container is already created, there is no way for you to mount the file inside unless you want to recreate the container.

Here is a workaround for this problem:

  1. Copy the sql file into the container
docker cp ./MYFILE.sql MYCONTAINER:/tmp/MYFILE.sql
  1. Now that the file is already inside the container at path /tmp/MYFILE.sql, you can execute your command like
docker exec -i MYCONTAINER mysql -uMYUSER -pMYPASS@ -f -D MYDATABASE < /tmp/MYFILE.sql

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=194801&siteId=1