0

I have a shell script and want to invoke via command line the mysql client

cat \
  "${SQL_DIR}/mysql-schema.sql" \
  "${SQL_DIR}/privileges.sql" \
  "${SQL_DIR}/mysql-import.sql" \
  "${SQL_DIR}/after.sql" \
  | docker exec -i "${PREPARE_NAME}" mysql -h127.0.0.1 -P 3306 -uroot -proot --default-character-set=utf8

it tells me

ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
read unix @->/var/run/docker.sock: read: connection reset by peer

If I do this from the command line everything works fine.

What shall I do?

5
  • Does a docker exec "${PREPARE_NAME}" mysql -h127.0.0.1 -P 3306 -uroot -proot --default-character-set=utf8 by itself connect to mysql? Does the script fail immediately or after a while? Commented Sep 13, 2017 at 12:54
  • By itself it works. Only within a bash script it fails. Commented Sep 19, 2017 at 1:44
  • Immediately or after some processing? Does it make a difference doing the files one at a time? Commented Sep 19, 2017 at 3:05
  • Needs more information. What command used to start the MySQL server? What are variables SQL_DIR and PREPARE_NAME? What is the host OS? What version Docker (docker version)? What is the current folder (pwd)? Commented Sep 19, 2017 at 3:06
  • $SQL_DIR and $PREPARE_NAME are just variables in the script and are not necessary for reproducing the problem. cat ... | docker exec -i container-name mysql -h127.0.0.1 -uroot -proot doesn't work within a bash script. The container has a mysql client. Commented Sep 20, 2017 at 8:10

1 Answer 1

0

You need mysql to be installed on your computer. Even if you handle Docker with the shell script: you really just need it on the computer that runs the shell script. Then you will get rid of

/home/.../some_bash_script.sh: line 123: mysql: command not found

and

ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)

On your computer, run:

sudo apt-get update && sudo apt-get install mysql-server
Sign up to request clarification or add additional context in comments.

Comments

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.