Error 2002 when running mysql (with sudo as well)

856 Views Asked by At

I'm trying to use MySQL to make a login system and I keep getting this error.

winfinity@pcname:~$ mysql
ERROR 2002 (HY000): can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' 
(2)

I've tried multiple answers. Can someone help?

1

There are 1 best solutions below

0
On
winfinity@pcname:~$ mysql
ERROR 2002 (HY000): can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' 
(2)

The above error implies the file /var/run/mysqld/mysqld.sock is missing, it can happen if mysql-server is not installed.

sudo apt-get install mysql-server

But if mysql-server is installed properly and is running, then check for config files.

/etc/my.cnf (socket file config may be /tmp/mysql.sock)
 OR
/etc/mysql/my.cnf (socket file config may be /var/run/mysqld/mysqld.sock)

In your case, it seems like the second config is set, so remove or rename /etc/mysql/my.cnf, let mysql use /etc/my.cnf, this may fix your problem.