简体   繁体   中英

Import local database to remote host Docker container

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM