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.