After going through the following links from SOF- I still am facing the issue and there is no reasoning or solution available.
References:
Mysql 5.7 is running as container in my local machine. Once the server is up, connecting to the server using root or the new user created fails over localhost/0.0.0.0/127.0.0.1. Even after disabling the firewald, the connectivity failed with the same error. I might have done something terribly wrong about this connectivity. Any advice would be helpful.
version: '3.5'
services:
service:
image: mysql:5.7
#build:
# context: ./
# dockerfile: Dockerfile
environment:
MYSQL_USER: user
MYSQL_PASSWORD: manage
MYSQL_ROOT_PASSWORD: manage
MYSQL_DATABASE: testapp
ports:
- published: 3306
target: 3306
Following is the output after docker-compose up -d
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
45ba02e6e457 mysql:5.7 "docker-entrypoint.s…" 52 seconds ago Up 50 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp
Below are the attempts to connect to the mysql container.
mysql -u root -h localhost -pmanage
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
mysql -u root -h 0.0.0.0 -pmanage
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
mysql -u root -h 127.0.0.1 -pmanage
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
IP of the running container works fine. But this is not a solution as the IP can change with time.
mysql -u root -h 172.31.0.2 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.30 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.
I am not looking for solutions with another docker command. How to connect to mysql container from docker host using mysql client.