MySQL ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

Some times you may face this error while connecting to database through MySQL client even though the services are running fine. Here its clear from the error that its connecting to the wrong socket. This is happens when MySQL service using socket path other than the default one.

In-order to fix this issue check the correct socket path for MySQL service.

#ps -aux | grep mysql

Update the same in mysql config file /etc/my.cnf.

[client]
socket=full-path-to-socket-file

Here we need to replace the socket file path accordingly. Pleas make sure that you are updating this parameter under '[client]' section.

Now we can connect to database through MySQL client without any issues.

That's all…

Leave a Reply

Your email address will not be published. Required fields are marked *