I am getting the following error when I try to connect to mysql:
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Is there a solution for this error? What might be the reason behind it?
I am getting the following error when I try to connect to mysql:
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Is there a solution for this error? What might be the reason behind it?
If you are on a recent RHEL, you may need to start mariadb (an open source mysql db) instead of the mysql db:
You should then be able to access mysql in the usual fashion:
Make sure you have enough space left in
/var
. If Mysql demon is not able to write additional info to the drive the mysql server won't start and it leads to the errorCan't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Consider using
This will help you keep disk usage down.
In my case I have moved socket file to another location inside
/etc/my.cnf
from/var/lib/mysql/mysql.sock
to/tmp/mysql.sock
Even after restarting the mysqld service, I still see the error message when I try to connect.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
The problem is with the way that the client is configured. Running diagnostics will actually show the correct socket path. eg
ps aux | grep mysqld
Works:
Does not Work:
You can fix this problem by adding the same socket line under
[client]
section inside mysql config.Most likely
mysql.sock
does not exist in/var/lib/mysql/
.If you find the same file in another location then symlink it:
For ex: I have it in
/data/mysql_datadir/mysql.sock
Switch user to mysql and execute as mentioned below:
That solved my problem
Make sure you started the server:
Then connect with root user:
I had to disable
explicit_defaults_for_timestamp
from my.cnf.