0

Help me to understand what's happening here with regards to connecting to the database:

root $ 
root $ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
root $ 
root $ docker image ls
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
basex/basexhttp      latest              3339bf6bc898        3 weeks ago         226MB
twilio/twilio-java   latest              611ab7ece1cf        4 weeks ago         993MB
mysql                latest              0d64f46acfd1        6 weeks ago         544MB
jetty                latest              5f997007f18d        7 weeks ago         522MB
jitsi/web            latest              1fad75476320        2 months ago        483MB
mysql/mysql-server   latest              8a3a24ad33be        2 months ago        366MB
hello-world          latest              bf756fb1ae65        8 months ago        13.3kB
root $ 
root $ docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d mysql/mysql-server:latest
7b119ef62a857a3b65189f9d79131513ac8d0872f9b93a3f9a507a96bf8d71d3
root $ 
root $ mysql -h127.0.0.1 -ppassword -uroot
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 2
root $ 
root $ mysql -h127.0.0.1 -p -uroot
Enter password: 
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 2
root $ 
root $ mysql -h127.0.0.1 -p -uroot
Enter password: 
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 2
root $ 
root $ docker exec -ti --user root mysql bash
bash-4.2# 
bash-4.2# mysql -u root -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
bash-4.2# 
bash-4.2# 
bash-4.2# 
bash-4.2# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 215
Server version: 8.0.21 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql> exit
Bye
bash-4.2# exit
exit
root $ 

No typo's involved, I just waited a bit and came back. Then it worked. Something about connection pooling perhaps?

1
  • it was pointed out to me that perhaps the container didn't finish init; I'll post the logs as well. – Nicholas Saunders Sep 21 '20 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.