• articles


  • db
  • mysql
  • docker

If you are using docker to run MySQL/MariaDB and you are trying to connect to the database from the machine running the docker instance you could run into this error:

Got error: 2002: “Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)” when trying to connect

This is due to the way MySQL/MariaDB connects in Unix/Linux system when you connect to localhost. It is different from what you would expect compared to other network-based programs where in it attempts to connect tot the local server by using Unix socket file. This will fail due to the database running within docker. Easy way to fix is by either adding a host or protocol as shown below:

mysql --host=
mysql --protocol=TCP