Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.8K
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda