Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose mysql import failed - the input device is not a TTY

I have any running containers. So i need import sql databases and try

docker-compose exec MYSQL_CONTAINERNAME mysql -uroot -p --database=MY_DB < /code/export_new.sql

But I have message "docker-compose exec -i MYSQL_CONTAINER NAME mysql -uroot -p --database=MY_DB < /code/export_new.sql" If I use "-i" or "-T" or "-it" parameters after command "... exec " I have message:

Usage: exec [options] [-e KEY=VAL...] SERVICE COMMAND [ARGS...]

Options:
    -d, --detach      Detached mode: Run command in the background.
    --privileged      Give extended privileges to the process.
    -u, --user USER   Run the command as this user.
    -T                Disable pseudo-tty allocation. By default `docker-compose exec`
                      allocates a TTY.
    --index=index     index of the container if there are multiple
                      instances of a service [default: 1]
    -e, --env KEY=VAL Set environment variables (can be used multiple times,
                      not supported in API < 1.25)
    -w, --workdir DIR Path to workdir directory for this command.

How I can to import my "export_new.sql" into mysql, which placed in container?

like image 655
Roman Avatar asked May 25 '18 11:05

Roman


2 Answers

Worked for me with

docker-compose exec -T MYSQL_CONTAINERNAME mysql databasename < data.sql
like image 126
lchachurski Avatar answered Oct 31 '22 18:10

lchachurski


Using docker-compose exec like this did not work (don't know why), but you can use docker exec. You just need to know the container name or id. Name is listed during docker-compose up or you can find out using docker-compose ps.

Here is an example command:

docker exec -i MYSQL_CONTAINERNAME mysql databasename < data.sql

Or you can combine docker-compose ps into it so that you only need to know the short name (defined in docker-compose.yml):

docker exec -i $(docker-compose ps -q MYSQL) mysql databasename < data.sql

Also, note that I had trouble using the above commands with -p flag so that it would ask for password interactively, but it worked when I passed the password in the initial command (e.g. mysql -uroot -pmypwd).

like image 33
Cvuorinen Avatar answered Oct 31 '22 17:10

Cvuorinen