22
votes

I am using PHP-mysql on Linux (RHEL 5.0) For First Time
When I tried to connect to MySQL from my PHP Script using mysqli_connect.
It Displayed The Following Error:

Can't connect to local MySQL server through socket '/var/mysql/mysql.sock'(2)

After googling for hour I found solution to this as stated here.

When I followed that approach and issued command:

service mysqld status

as a root user I got : mysql is dead but subsys locked Any one know how to solve this and cause of this error ?

Also

  • Restarting
  • Starting
  • And Stopping of MySQL
is Giving Output as: FAILED
But PHP is working fine. I've tested the phpinfo(); for Demo.
I've installed MySQL in /usr/local/mysql/bin. Can Anyone Help me in this ? Any help is appreciated.


Thanks in advance.

9
Restart the whole server - Hanky Panky
@Hanky웃Panky Tried it before posting the question. But it is of No use. - Vedant Terkar
Have you actually looked at the mysql log file to see what the error could possibly be rather than just wildly plucking stuff out of the air? - Cwissy
@VedantTerkar is there any permanent solution for this? I'm getting this every few hours - Gijo Varghese

9 Answers

67
votes

I had this problem with my OTRS server after I tried to update a to large package.

The solution was:

copy for safty:

cp /var/lock/subsys/mysqld /root/mysqld

than delete it

rm /var/lock/subsys/mysqld

than close all services that depends on mysql:

service httpd stop
service otrs stop

after that:

service mysqld restart
service httpd restart
service otrs restart

System is CentOS 6.x

6
votes
service mysqld restart

Simply restarting the mysqld worked fro me on Centos.

4
votes
  1. tail /var/log/mysqld.log to check the error log
  2. then do the following actions:

    rm /var/lock/subsys/mysqld chown -R mysql.mysql /var/run/mysqld

3
votes

first,make sure that /etc/init.d/mysqld is running from /usr/local/mysql/bin then,kill mysqld ,delete the lock file and restart it.

1
votes

This (and all sorts of other weird errors) can also happen if you have a full disk. In my case, my /var partition had filled up. Freeing up space allowed mysqld to restart again.

1
votes

First find the PID number of mysqld:

 1. Use top | grep mysqld
 2. kill -9 PID

Safe method, works fine with Cent OS

0
votes

Rebooting the server worked for me. Please remember to start all the services once you reboot in case you haven't added 'chkconfig' for them, lets say httpd, named and mysql.

0
votes

i use command kill, step by step:

  1. use command service mysqld status for find PID mysqld
  2. kill -9 PID
  3. use command service mysqld status again for find PID mysqld
  4. kill -15 PID
  5. check again with command service mysqld status , check until the PID dead OR subsys locked
  6. use command service mysqld start
0
votes

The problem I meet in the project is because of the disk space run out.

The server that MySQL is running run out the disk space, business project's log is too large. The result is that MySQL restart failed.

It is one probability and you can have a try.

du -sh *

and

service mysqld restart