Got this error today when starting mysql on xshell:
[root@mini1 ~]# service mysql start
Starting MySQL SUCCESS!
[root@mini1 ~]# mysql -u root -proot
ERROR 2002 (HY000): Can't connect to local MySQL server through socket ' /var/li b/mysql/mysql.sock' (2)
Starting MySQL SUCCESS!
[root@mini1 ~]# mysql -u root -proot
ERROR 2002 (HY000): Can't connect to local MySQL server through socket ' /var/li b/mysql/mysql.sock' (2)
Then closing mysql also reported an error:
[root@mini1 ~]# service mysql stop
ERROR! MySQL server PID file could not be found!
ERROR! MySQL server PID file could not be found!
Solution:
First look at the process
[root@
irxpert-test /]# ps aux |grep mysq*
root 10274 0.0 0.0 68160 1336 ? S 13:43 0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/irxpert-test.pid
mysql 10353 0.0 1.0 344360 39464 ? Sl 13:43 0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/irxpert-test.err --pid-file=/var/lib/mysql/irxpert-test.pid
root 11884 0.0 0.0 63384 760 pts/1 S+ 15:44 0:00 grep mysq*
mysql 10353 0.0 1.0 344360 39464 ? Sl 13:43 0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/irxpert-test.err --pid-file=/var/lib/mysql/irxpert-test.pid
root 11884 0.0 0.0 63384 760 pts/1 S+ 15:44 0:00 grep mysq*
If you see the above content, it means that the Mysql process is stuck, and then you need to close these stuck processes.
[root@centos mysql]# kill -9
10274
[root@centos mysql]# kill -9
10353
It's ok to start Mysql