• Register
3,890 points
11 5 1

If you are running in this error while trying to connect to a local MySQL Server then it means that your MYSQL server is not installed or the file does not exist in /var/lib/mysql/.

Solutions:

There are a couple of solutions for this error;

Check the status of MySQL:

First, check to see whether mysqld service is running or not. If not then start it:

service mysqld start

Then try to connect again.

Connect to 127.0.0.1:

Try to connect to 127.0.0.1 instead of localhost. Because when the user connects to the localhost, it will use a socket connector but if you connect to 127.0.0.1 then TCP/ID connector will be used. So when the socket connector is not working then connect to 127.0.0.1 instead.

Edit file my.cnf:

Find the file my.cnf to edit and add the following lines;

[mysqld]

socket = /var/lib/mysql/mysql.sock

[client]

socket = /var/lib/mysql/mysql.sock

Restart mysql and try to connect again.

Symlink:

In some cases, mysql.sock can be located in another folder. You have to find it and symlink it. You can find it in /tmp/mysql.sock or /data/mysql_datadir/mysql.sock.

Example:

If the file is located in /tmp/mysql.sock

Then symlink it:

ln –s /var/lib/mysql.sock /tmp/mysql.sock

Restart mysql and try to connect again.

3,890 points
11 5 1