Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.8K
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda