0

I used my local mysql Docker container to dump a small and trivial test database. See:

docker exec -it [container] mysqldump -u root test > dump.sql

I'm trying to import dump.sql to a remote mysql Docker container with:

docker exec -i [container] mysql -u root -h xxx.xxx.xx.xxx -p password test < dump.sql

However it returns the help for mysql so I must have improper usage. What am I missing?

1
  • 1
    -it is not needed in when running mysqldump. The flag -t should only be used when running interactively. Using it non-interactively could lead to a different result (for instance adding CR "carriage return") Commented May 1, 2022 at 7:47

1 Answer 1

1

Below command works for me.

Importing Database Dump into Docker Command:

podman exec -i [CONTAINER ID] sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD" [DATABASE]' < restspring_mysql_db_dump.sql

DETAILED STEPS:

Pull MySQL Image Command:

podman pull mysql:8

Run Podman Command:

podman run -d --name mysql-8 -p 3316:3316 -e MYSQL_ROOT_PASSWORD=root mysql:8

Export Database Command:

mysqldump -u root -p restspring > restspring_mysql_db_dump.sql

List Containers Command:

podman ps
                                                                                        
CONTAINER ID  IMAGE                      COMMAND     CREATED         STATUS             PORTS                   NAMES
c6071ab6a192  docker.io/library/mysql:8  mysqld      45 minutes ago  Up 45 minutes ago  0.0.0.0:3316->3316/tcp  mysql-8

Importing Database Dump into Docker Command:

podman exec -i c6071ab6a192 sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD" mysql' < restspring_mysql_db_dump.sql
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! Using the shell command as part of my Docker command did the trick. Is shell the command necessary because the Docker command to import does not include -t ?
Hi @Astrodude11, not sure. I am still in learning phase

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.