Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.8K
Views
Docker mysql: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I am trying to connect to mysql server using mysql cli. Image was created using following command:

docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=****** -d mysql

The docker container is running. docker ps prints:

johnd@john-pc:~$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
598c0f8680dc        mysql               "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes        3306/tcp, 33060/tcp    some-mysql

When i enter the following command: mysql -h 127.0.0.1 -P 3306 -u root -p it returns:

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

I also tried with --protocol=tcp attribute. How do i connect from client to mysql server running on docker using terminal from client machine (not from another docker)

EDIT: I also tried connecting to mysql using this command:

docker run -it --rm mysql mysql -h127.0.0.1 -uexample-user -p

It returns the same error

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

mysql -h 127.0.0.1 -P 3306 -u root -p

You are connecting to your localhost's sql server but you didn't map the docker's container port to the host. Try mapping the port to your host by this:

docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=****** -d -p 3306:3306 mysql

Then retry:

mysql -h 127.0.0.1 -P 3306 -u root -p

over 4 years ago · Santiago Trujillo Report

0

same error to me, just remember start mysql service first in your container.

exec in your container

/etc/init.d/mysql start
over 4 years ago · Santiago Trujillo Report

0

Using internal docker IP like 127.0.0.1 didn't work for me

I used my POD's IP and it worked

mysql -h 10.10.10.41 -P 3306 -u root -p

I still don't understand why I wasn't able to login and before and after this command I was able to login

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!