I am getting the following error when I try to log into mysql from the CentOS 7 terminal of the machine where mysql is installed:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
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.) I tried cd /var/lib/mysql
and ls -al
, but the resulting list of files did not contain mysql.sock
.
2.) 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.
3.) So I opened another terminal window and ran systemctl status mysqld
, only to see that mysqld was again started. But the error persists.
4.) I tried find / -name "mysql.sock"
but the response was find: ‘/run/username/1000/gvfs’: Permission denied
.
5.) Then I read this posting and tried mysqladmin | grep d.sock
but there were no results.
6.) 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.
7.) 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.
8.) 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
9.) 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.'
10.) 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 my.cnf
is corrupted. If so, how can I fix it? Here is the link to a copy of my.cnf
on a file sharing site.
11.) I then tried RolandoMySQLDBA's suggestion and tried:
[root@localhost]# mysqladmin -h127.0.0.1 -P 3306 --protocol=tcp -uroot -p shutdown
Enter password:
mysqladmin: connect to server at '127.0.0.1' failed
error: 'Can't connect to MySQL server on '127.0.0.1' (111)'
Check that mysqld is running on 127.0.0.1 and that the port is 3306.
You can check this by doing 'telnet 127.0.0.1 3306'
[root@localhost etc]# telnet 127.0.0.1 3306
bash: telnet: command not found...
But you can see I was not able to connect. So I took the following steps, which include more detail of a preceding step above:
[root@localhost etc]# systemctl status mysqld -l
mysqld.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
Dec 15 15:38:17 localhost.localdomain systemd[1]: Failed to start MySQL Community Server.
Dec 15 15:38:17 localhost.localdomain systemd[1]: Unit mysqld.service entered failed state.
Dec 15 15:38:17 localhost.localdomain systemd[1]: mysqld.service holdoff time over, scheduling restart.
Dec 15 15:38:17 localhost.localdomain systemd[1]: Stopping MySQL Community Server...
Dec 15 15:38:17 localhost.localdomain systemd[1]: Starting MySQL Community Server...
Dec 15 15:38:17 localhost.localdomain mysqld_safe[12886]: 141215 15:38:17 mysqld_safe Logging to '/var/log/mysqld.log'.
Dec 15 15:38:17 localhost.localdomain mysqld_safe[12886]: 141215 15:38:17 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Dec 15 15:38:17 localhost.localdomain mysqld_safe[12886]: 141215 15:38:17 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Dec 15 15:38:25 localhost.localdomain systemd[1]: Stopping MySQL Community Server...
Dec 15 15:38:25 localhost.localdomain systemd[1]: Stopped MySQL Community Server.
[root@localhost etc]# systemctl start mysqld
Failed to issue method call: Unit mysqld.service failed to load: No such file or directory.
[root@localhost etc]# yum install mysql
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: repos.lax.quadranet.com
* epel: mirrors.kernel.org
* extras: repos.lax.quadranet.com
* updates: repos.lax.quadranet.com
Package mysql-community-client-5.6.22-2.el7.x86_64 already installed and latest version
Nothing to do