0

I have started Mysql instance in docker by issuing command docker run -d -p 3306:3306 --name some-mysql -e MYSQL_ROOT_PASSWORD=supersecret some-mysql . But when i am trying to login as root by issuing command mysql -u root -p and giving password superscret . I am getting below provided error.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Mostafa Hussein
  • 11,063
  • 3
  • 36
  • 61
Sritam Jagadev
  • 955
  • 4
  • 18
  • 46
  • Possible duplicate of [error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' -- Missing /var/run/mysqld/mysqld.sock](https://stackoverflow.com/questions/11990708/error-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysq) – Mebin Joe Mar 21 '19 at 05:06
  • did you check the container logs? did it start smoothly? – ItayB Mar 21 '19 at 05:38
  • superscret != supersecret – Lawrence Cherone Mar 21 '19 at 09:13

1 Answers1

1

I am assuming that you are executing mysql -u root -p from the host itself not inside the container.

So based on my assumption the container does not have a mysql.sock inside the host itself when you run it, so you need to change the default protocol.

This command will connect through tcp instead of socket

mysql --protocol=tcp -u root -p
Mostafa Hussein
  • 11,063
  • 3
  • 36
  • 61