Docker Community Forums

Share and learn in the Docker community.

Import SQL into running mysql container

docker

(Sthompso) #1

I can’t figure out how to import a sql file into an already running mysql container. The original sql file is on the host machine and i copied it over like this:

docker cp database_schema.sql my-mysql:/database_schema.sql

I can then see it in the root dir on the container but when i try to import it I get a “No such file or directory”.

[jenkins@or1010050215222 ~]$ docker exec -i my-mysql ls | grep .sql
database_schema.sql
[jenkins@or1010050215222 ~]$ docker exec -i my-mysql mysql < database_schema.sql
-bash: database_schema.sql: No such file or directory

What am I doing wrong?

Thanks,
Shay


(Sthompso) #2

I just found out that its actually injecting from the local host not the container so i don’t need the copy. Even better!


(David Maze) #3

https://hub.docker.com/_/mysql/ is probably worth a read-through, especially the “Initializing a fresh instance” section.