23

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.

Vedant Terkar
  • 4,553
  • 8
  • 36
  • 62

9 Answers9

69

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

Jonathan H.
  • 816
  • 7
  • 7
  • You know what, this question is now becoming a year old (Happy B'day to it :), in advance ), but I did the same at that time and that solved my problem. But I failed to post it as my answer here. So Thanks for posting. +1 and accepting this. Cheers :)! – Vedant Terkar Sep 05 '14 at 06:20
  • Thanks, mate. This did it. As mine's not CentOS I just didn't need to handle the "otrs". Cheers. – Felipe May 13 '16 at 11:59
  • 2
    +1. I just had this problem on a Amazon instance and this solved it. Two short notes: the /var/lock/subsys/mysqld file was empty (0 bytes); the service otrs was not installed on the machine. – JonyD Aug 18 '16 at 07:19
  • Thanks a lot! However, I am looking for now for a root cause as it repeats itself every 24h :( – Jovan Perovic Oct 03 '16 at 07:31
  • @JovanPerovic is there any permanent solution for this? I getting this error every few hours. It's not easy to log in each time and fix this – Gijo Varghese Nov 18 '16 at 01:00
  • @GijoVarghese: I was able to confirm that OS OOM was triggered every single time prior to crash. I tried to pin point the root cause of OOM, but the crash would happen sometimes in the middle of the work hours and sometimes during the nightly backup (while doing nightly `mysql_dump`). Finally, I ran out of options and decided to contact the provider which said that my **kernel** was out of date and they have upgraded it to the latest. From that day on, I had not a single crash! Somehow, I find it hard to believe that it was kernel version and not something more serious, I have no proof. – Jovan Perovic Nov 18 '16 at 02:14
  • @JovanPerovic I bought the basic plan from DigitalOcean (Centos 6.8 with 512MB ram). But if its a kernel issue, digitalocean would have already fixed it. I doubt its due to 512MB ram. Going to upgrade and try – Gijo Varghese Nov 18 '16 at 02:27
  • Cool, try doing that. You might as well find something useful in my own question on SF: http://serverfault.com/questions/812629/weeding-out-the-oom-and-consecutive-mysqld-crash – Jovan Perovic Nov 18 '16 at 10:02
  • Well I did little research and followed these steps: first check what is the available swap memory and then check which process is consuming more memory using command top -H and kill that process and then restart the mysqld – Pankaj Kumar Katiyar Dec 15 '16 at 10:55
  • This seems to happen on systems simply running out of memory where mysqld gets killed by the operation system OOM killer. – sjas May 22 '18 at 08:22
6
service mysqld restart

Simply restarting the mysqld worked fro me on Centos.

Mayank Jaiswal
  • 12,338
  • 7
  • 39
  • 41
4
  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

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
3

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.

fsgf
  • 31
  • 1
  • Thanks For Your reply. Can you please elaborate how to do that? Specially The First part : `make sure that /etc/init.d/mysqld is running from /usr/local/mysql/bin`. because I'm very new to linux. I'm a Windows user. – Vedant Terkar Oct 15 '13 at 12:12
  • Thanks for spending you time in solving this. +1. – Vedant Terkar Sep 05 '14 at 06:22
1

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.

Dale C. Anderson
  • 2,280
  • 1
  • 24
  • 24
1

First find the PID number of mysqld:

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

Safe method, works fine with Cent OS

Abhik Bose
  • 11
  • 3
0

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.

Saladin
  • 1
  • 1
0

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

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

accfcx
  • 29
  • 1