mysql.sock not found, where can i find it?

10,367

Realise this is an old post, but came across this myself just now and found it very hard to find the proper solution. I solved it by doing the following:

  1. Install zlib:

    32-Bit Debian/Ubuntu: apt-get install zlib1g
    64-Bit Debian/Ubuntu: apt-get install lib32z1
    32/64-Bit Fedora: yum install zlib.i686
    32/64-Bit Mandriva: urpmi zlib1
    32-Bit SUSE: zypper install libz1
    64-Bit SUSE: zypper install libz1-32bit
    
  2. Connect to 127.0.0.1 instead of localhost if that option is available to you. With MySQL connecting via 127.0.0.1 and localhost use different methods (TCP for the former, Sock for the latter)

  3. Make sure your firewall isn't blocking ports internally, perhaps consider disabling it temporarily to make sure this isn't the case.

Share:
10,367
CodeMed
Author by

CodeMed

Updated on June 21, 2022

Comments

  • CodeMed
    CodeMed almost 2 years

    On a CentOS 7 machine, I am getting the following error when I try to log into mysql from the terminal:

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

    I then tried cd /var/lib/mysql and ls -al, but the resulting list of files did not contain mysql.sock. So where can I find mysql.sock and how can I resolve this error?

    Here are a number of things I have tried already:

    1.) When I saw that systemctl status mysqld showed that mysql was stopped, I also tried systemctl start mysqld but the terminal just gave an unresponsive cursor without a new prompt, as if it were held up waiting for something, but it remained in that limbo state indefinitely.

    2.) So I opened another terminal window and ran systemctl status mysqld, only to see that mysqld was again started. But the error persists.

    3.) I tried find / -name "mysql.sock" but the response was find: ‘/run/username/1000/gvfs’: Permission denied.

    4.) Then I read this posting and tried mysqladmin | grep d.sock but there were no results.

    5.) I even resorted to yum remove mysql followed by yum install mysql, but then mysql -u root still gives the same original error at top of this posting.

    6.) And then I read this other posting, but mysqladmin variables gives the same error that it cannot connect because the mysql.sock cannot be found.

    7.) And I tried ln -s /tmp/mysql.sock /var/mysql/mysql.sock but the same error persisted even though a link to mysql became visible when I tried cd /var/lib/mysql/ and ls -al

    8.) Since the problem may have to do with the fact that systemctl start mysqld gets hung up, I read this posting and tried chown -R mysql:mysql /var/lib/mysql and systemctl start mysqld but the result is Failed to issue method call: Unit mysqld.service failed to load: No such file or directory.

    9.) I then read this posting, which caused me to run mysql --help | grep "Default options" -A 1. The result printed the locations where mysql looks for my.cnf. I thus checked every location, and there was no my.cnf file to be found. But I did find a mysql.cnf.rpmsave, so I tried mv mysql.cnf mysql.cnf.rmpsave. This caused there to be a my.cnf in the expected directory, but systemctl status mysqld says that mysqld is not found. I tried yum install mysql again, but it told me that mysql is already installed. So I suspect that the newly renamed my.cnf is corrupted. If so, how can I fix it? Here is the link to a copy of the newly renamed my.cnf on a file sharing site.

  • CodeMed
    CodeMed over 9 years
    The link you sent did not work. Step 2 showed that there was NOT mysql.sock in either folder. And /usr/bin/mysql_install_db in step 6 threw an error. Anyone can google a link to a tutorial like the one in your answer. The number of attempts listed in my original post above shows I have already done a lot of web research on this. I was hoping someone would actually look at this instead of just doing a quick google search that I have already done before posting.
  • CodeMed
    CodeMed almost 7 years
    Thank you and+1 for taking the time to add insight into this old question.