sudo docker run -i -t f92f0896ed95 /bin/bash
[Entrypoint] MySQL Docker Image 5.7.21-1.1.3
bash-4.2# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
bash-4.2#
Asked
Active
Viewed 620 times
0

Gilles Quénot
- 173,512
- 41
- 224
- 223
-
Mentioned here too: https://github.com/docker-library/mysql/issues/360 – Spangen Feb 13 '18 at 17:50
-
Possible duplicate of [Installing MySQL in Docker fails with error message "Can't connect to local MySQL server through socket"](https://stackoverflow.com/questions/23234379/installing-mysql-in-docker-fails-with-error-message-cant-connect-to-local-mysq) – ldg Feb 14 '18 at 04:34
2 Answers
0
You have to configure ~/.my.cnf
with your credentials, then mysql
shell can be opened directly.
Example of content :
[client]
user=dba
password=foobar
# depends of what is configured, can be a hostname or 127.0.0.1, it's matter :
host=localhost
Or if you can't configure the image, do this :
mysql -h localhost -p
Then you will be prompted to enter the password

Gilles Quénot
- 173,512
- 41
- 224
- 223
-
i am using docker...so what is can type after bash-4.2# for entering into mysql shell – Feb 13 '18 at 17:47
0
First run your image standard and then connect to the running image with:
docker exec -it f92f0896ed95 /bin/sh

Ivonet
- 2,492
- 2
- 15
- 28
-
Agreed, I would make sure the container starts up without errors. Then you can connect to it as above, or use `mysql` instead of `/bin/sh` to connect to the mysql client directly via the exec command -- adding whatever params you need (host, username, etc). Note that "localhost" in a Unix-type environment will try to use the socket by default, so try 127.0.0.1 if "localhost" doesn't work -- but the socket _should_ work. – ldg Feb 14 '18 at 04:33