3

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.

closed as off-topic by hot2use, RDFozz, mustaccio, Max Vernon, LowlyDBA Mar 15 '18 at 14:36

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Too localized - this could be because your code has a typo, basic error, or is not relevant to most of our audience. Consider revising your question so that it appeals to a broader audience. As it stands, the question is unlikely to help other users (regarding typo questions, see this meta question for background)." – hot2use, RDFozz, mustaccio, Max Vernon, LowlyDBA
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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 Sep 15 '17 at 8:21
  • are you sure mysqld is actually running? what is the output of ps aux|grep mysql – jerichorivera Sep 16 '17 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 – user7432810 Sep 18 '17 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 – Mauricio Cacho Sep 18 '17 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) – user7432810 Sep 19 '17 at 13:27
1

Checks:

  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. – user7432810 Sep 21 '17 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 Sep 21 '17 at 11:08

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