I am on Cento 6.9 and trying to solve a problem with Mysql.

When I try to start mysql I get:

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

As per recommendation of gurus here I tried to find mysql.sock file. I have tried:

find . -name mysql.sock

But could not find anything. Any idea where my mysql.sock is?

I have also tried:

lsof -U -c mysqld -a

which returns nothing.

  • sudo find / -name mysqlsock, but I doubt if it'll be there as the mysql daemon isn't working! What is the command you are issuing to start mysql?
    – Vérace
    Commented Sep 15, 2017 at 8:21
  • are you sure mysqld is actually running? what is the output of ps aux|grep mysql Commented Sep 16, 2017 at 12:34
  • This is the output: root 1484 0.0 0.0 112660 976 pts/0 S+ 17:18 0:00 grep --color=auto mysql Commented Sep 18, 2017 at 12:49
  • From that output, mysql isn't running; how are you trying to start it? If you can put your cnf file could help Commented Sep 18, 2017 at 17:48
  • This is how I try to start it: # mysql start and I get : ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) Commented Sep 19, 2017 at 13:27

1 Answer 1



  1. Is the server actually running locally?
  2. Grep for mysql.sock in my.cnf and provide results
  3. Run: sudo /usr/sbin/lsof | grep mysql.sock
  4. Check (i.e. grep) mysqld err logs to see if its remarking about mysql.sock or any other startup issues.
  5. Check permissions on the MySQL directories, i.e. /var/lib/mysql/ should be read/writable by the mysql group and sufficient permissions for users to reach the socket file.
  6. How are you starting the mysqld process? The error looks more like a client connection issue?

While you can re-install solutions I have used in the past include:

  1. Touch the socket file and make sure it is owned by the mysql group and user.

    ls -l /tmp/mysql.sock
    srwxrwxrwx 1 mysql mysql 0 Jun 15 15:08 /tmp/mysql.sock

    Check the my.cnf for the setting for where the socket is.

    You can use the following steps to re-create the socket. Just change the name to reflect the expected name of the socket as given by my.cnf under the [mysqld] and [client] sections.

    sudo touch /tmp/mysql.sock
    sudo chown mysql:mysql /tmp/mysql.sock
    sudo chmod 0777 /tmp/mysql.sock
  2. Starting mysqld as a service via systemctl mysql start etc.

  3. Make sure you are using sudo etc. as most command require root level privileges to work correctly.
  • I reinstalled the whole mysql now and I can see mysql.sock inside mysql folder. It wasn't there before. So for it has happened twice and I only restore the database by reinstalling mysql altogether. Commented Sep 21, 2017 at 7:39
  • @user7432810 I've added some more information that may be helpful in future. I realise it will be unlikely that you can provide more information after re-installing however.
    – Voltaire
    Commented Sep 21, 2017 at 11:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.