mysql.sock not found, where can i find it?
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:
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
Connect to
127.0.0.1
instead oflocalhost
if that option is available to you. With MySQL connecting via127.0.0.1
andlocalhost
use different methods (TCP for the former, Sock for the latter)Make sure your firewall isn't blocking ports internally, perhaps consider disabling it temporarily to make sure this isn't the case.
CodeMed
Updated on June 21, 2022Comments
-
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
andls -al
, but the resulting list of files did not containmysql.sock
. So where can I findmysql.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 triedsystemctl 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 wasfind: ‘/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 byyum install mysql
, but thenmysql -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 themysql.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 triedcd /var/lib/mysql/
andls -al
8.) Since the problem may have to do with the fact that
systemctl start mysqld
gets hung up, I read this posting and triedchown -R mysql:mysql /var/lib/mysql
andsystemctl start mysqld
but the result isFailed 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 wheremysql
looks formy.cnf
. I thus checked every location, and there was nomy.cnf
file to be found. But I did find amysql.cnf.rpmsave
, so I triedmv mysql.cnf mysql.cnf.rmpsave
. This caused there to be amy.cnf
in the expected directory, butsystemctl status mysqld
says thatmysqld
is not found. I triedyum install mysql
again, but it told me thatmysql
is already installed. So I suspect that the newly renamedmy.cnf
is corrupted. If so, how can I fix it? Here is the link to a copy of the newly renamedmy.cnf
on a file sharing site. -
CodeMed over 9 yearsThe link you sent did not work.
Step 2
showed that there was NOTmysql.sock
in either folder. And/usr/bin/mysql_install_db
instep 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 almost 7 yearsThank you and+1 for taking the time to add insight into this old question.