“ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock'” Error and Solution

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/error-2002-hy000-cant-connect-local-mysql-server-socket-var-run-mysqld-mysqld-sock-error-solution/
PINTEREST
PINTEREST
INSTAGRAM

MySQL service provides different connection methods. We generally prefer TCP/IP way where connection is established over Network Socket. There is alternative way named Socket which is connected over local system. During connection we may get error like Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ . In this tutorial we will look to solve this problem.

Solution 1 – Start The Service

Socket is created by the MySQL service and if the service is not the started the socket will not created. So starting the service is the first step to solve this problem. We will use systemctl  command.

AND check service status

Solution 1 - Start The Service

Solution 1 – Start The Service

Solution 2 – Check The Socket Path

As we try to connect to the socket the path of the Socket should be correctly specified. By the default the socket is /var/run/mysqld/mysqld.sock and this may be changed. We can check current path configuration of the socket from config file which is /etc/mysql/debian.cnf .

Solution 2 - Check The Socket Path

Solution 2 – Check The Socket Path

Solution 3 – Check Data Directory Permissions

One of the another reason to get related error is MySQL server do not started. This may be cause with wrong directory permissions. We should check MySQL service data path permissions with the following command and make them writeable by the MySQL service.

LEARN MORE  Linux Netstat Command With Examples

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)