On a CentOS 7 machine, I get the following error when trying to login to mysql from a terminal:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Then I tried cd /var/lib/mysql and ls -al , but as a result the list of files did not contain mysql.sock . So where can I find mysql.sock and how to resolve this error?
Here are a few things I've already tried:
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 had been delayed, waiting for something, but it remained in this state uncertainties for an indefinite period.
2.) So, I opened another terminal window and ran systemctl status mysqld , only to see that mysqld was running again. But the error persists.
3.) I tried find / -name "mysql.sock" , but the answer was find: '/run/username/1000/gvfs': Permission denied .
4.) Then I read this publication and tried mysqladmin | grep d.sock mysqladmin | grep d.sock , but 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 the top of this post.
6.) And then I read this other publication , but mysqladmin variables gives the same error that it cannot connect, because mysql.sock cannot be found.
7.) And I tried ln -s /tmp/mysql.sock /var/mysql/mysql.sock , but the same error persisted, although the mysql link became visible when I tried cd /var/lib/mysql/ and ls -al
8.) Since the problem may be due to the fact that systemctl start mysqld gets stuck, I read this publication 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.) Then I read this publication , which made me start mysql --help | grep "Default options" -A 1 mysql --help | grep "Default options" -A 1 . The result printed the places where mysql looking for my.cnf . So I checked every location and my.cnf file was not found. But I found mysql.cnf.rpmsave , so I tried mv mysql.cnf mysql.cnf.rmpsave . This resulted in my.cnf in the expected directory, but systemctl status mysqld says that mysqld not found. I tried yum install mysql again, but I was told that mysql already installed. Therefore, I suspect that the recently renamed my.cnf corrupted. If so, how can I fix it? Here is a link to a copy of the recently renamed my.cnf into a site sharing file.