Mariadb-docker: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")

Created on 12 Apr 2018  路  2Comments  路  Source: MariaDB/mariadb-docker

When I try to run mysql command through bash, I get this error.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")

This is my docker-compose file

db:
    image: mariadb:10.0.34
    volumes:
      - ./latest_dump.sql:/docker-entrypoint-initdb.d/latest_dump.sql
    restart: always
    ports:
      - "3307:3306"
    environment:
      MYSQL_ROOT_PASSWORD: *******

How can I solve this issue?

Most helpful comment

From the error message, I can only assume you're using the mysql client from your host and trying to connect it to localhost. The mysql client has a special case where it converts a hostname of localhost to the default Unix socket path instead, hence the error you're seeing. Swap localhost for 127.0.0.1 and it'll probably work.

In the future, these sorts of questions/requests would be more appropriately posted to the Docker Community Forums, the Docker Community Slack, or Stack Overflow.

All 2 comments

From the error message, I can only assume you're using the mysql client from your host and trying to connect it to localhost. The mysql client has a special case where it converts a hostname of localhost to the default Unix socket path instead, hence the error you're seeing. Swap localhost for 127.0.0.1 and it'll probably work.

In the future, these sorts of questions/requests would be more appropriately posted to the Docker Community Forums, the Docker Community Slack, or Stack Overflow.

I encountered the same problem, and I confirm, it works with host explicitly set with 127.0.0.1
mysql -u ${mariadb_username} -p${mariadb_password} -h 127.0.0.1
Thanks @tianon

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shawnweeks picture shawnweeks  路  4Comments

rahonalab picture rahonalab  路  5Comments

shaula picture shaula  路  3Comments

foxx picture foxx  路  4Comments

paulz1 picture paulz1  路  8Comments