Saturday, March 17, 2012

ERROR 2002 (HY000): Can't connect to local MySQL server through socket

root@localhost# mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
root@localhost# vi /etc/mysql/my.cnf

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port = 3306
#socket = /var/run/mysqld/mysqld.sock # This path does not exist, default value.
socket = /opt/lampp/var/mysql/mysql.sock # This path exists and has correct permissions

Verify the name of the user that mySQL is running under:

root@localhost# ps aux |grep my |grep -v grep
root      1848  0.0  0.1   1832   580 pts/0    S    03:02   0:00 /bin/sh /opt/lampp/bin/mysqld_safe --datadir=/opt/lampp/var/mysql --pid-file=/opt/lampp/var/mysql/dvwa-testbed.pid
nobody    1974  0.0  5.0 129256 25948 pts/0    Sl   03:02   0:00 /opt/lampp/sbin/mysqld --basedir=/opt/lampp --datadir=/opt/lampp/var/mysql --user=nobody --log-error=/opt/lampp/var/mysql/dvwa-testbed.err --pid-file=/opt/lampp/var/mysql/dvwa-testbed.pid --socket=/opt/lampp/var/mysql/mysql.sock --port=3306

Make sure the file exists and has the proper permissions:


root@localhost# ls -al  /opt/lampp/var/mysql/mysql.sock
srwxrwxrwx 1 nobody nogroup 0 2012-03-16 03:02 /opt/lampp/var/mysql/mysql.sock

This worked for me, ymmv.
Post a Comment