Down site – Error establishing a database connection

November 1, 2015 2.1k views
WordPress MySQL

Hi all! So, my site has been down several times this past few days. I am running a self hosted wordpress site using Umbuntu.

The other day I had an error establishing a database connection so when I run curl -I and tail, I didn't saw anything particular so when I restarted the apache the site run back normally.

However, today the site was down again and when I run tail it showed that apparently I lost connection to MySql database therefore I did a series of apache and mysql restarting and now my site is back again.

My question is, what normally drives this kind of errors and if ever there is a problem with mysql, how can I fix this? Below are the logs from the latest moment my site was down.

It is down again and when I try curl:

HTTP/1.1 500 Internal Server Error
Date: Sun, 01 Nov 2015 08:36:40 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.11
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Pragma: no-cache
Connection: close
Content-Type: text/html; charset=utf-8

And here's the tail result:

[Sun Nov 01 07:10:58.648191 2015] [:error] [pid 17859] [client 5.8.66.115:47686] WordPress database error Lost connection to MySQL server during query for query select val from wpwfConfig where name='disableConfigCaching' made by include('wp-load.php'), requireonce('wp-config.php'), requireonce('wp-settings.php'), includeonce('/plugins/wordfence/wordfence.php'), wordfence::install_actions, wfCache::setupCaching, wfConfig::get, wfDB->querySingle

I don't understand most of the problem which the tail gave me except for the lost server from MySql. I wish to fix this problem and I think restarting it is just something temporary because if there's something bigger behind this downtime, I really wish to fix now.

This forum has been so helpful and I really enjoy the learning progress everytime I recieve a downtime but recently I'm getting quite a bit of traffic and the down time has been affecting the flow :(

Thanks all!

1 comment
  • I'm receiving some heavy traffic from the IP you're mentioning here (5.8.66.115) :(
    Cloudflare is helping me out!

    5.8.66.115 - - [02/Nov/2015:16:42:44 -0500] "POST /xmlrpc.php HTTP/1.0" 404 463 "-" "Mozilla/4.0 (compatible: MSIE 7.0; Windows NT 6.0)"
    5.8.66.115 - - [02/Nov/2015:16:42:45 -0500] "POST /xmlrpc.php HTTP/1.0" 404 463 "-" "Mozilla/4.0 (compatible: MSIE 7.0; Windows NT 6.0)"
    5.8.66.115 - - [02/Nov/2015:16:42:46 -0500] "POST /xmlrpc.php HTTP/1.0" 404 463 "-" "Mozilla/4.0 (compatible: MSIE 7.0; Windows NT 6.0)"
    5.8.66.115 - - [02/Nov/2015:16:42:47 -0500] "POST /xmlrpc.php HTTP/1.0" 404 463 "-" "Mozilla/4.0 (compatible: MSIE 7.0; Windows NT 6.0)"
    5.8.66.115 - - [02/Nov/2015:16:42:49 -0500] "POST /xmlrpc.php HTTP/1.0" 404 463 "-" "Mozilla/4.0 (compatible: MSIE 7.0; Windows NT 6.0)"
    5.8.66.115 - - [02/Nov/2015:16:42:49 -0500] "POST /xmlrpc.php HTTP/1.0" 404 463 "-" "Mozilla/4.0 (compatible: MSIE 7.0; Windows NT 6.0)"
    5.8.66.115 - - [02/Nov/2015:16:42:49 -0500] "POST /xmlrpc.php HTTP/1.0" 404 463 "-" "Mozilla/4.0 (compatible: MSIE 7.0; Windows NT 6.0)"
    
3 Answers

Most likely OOM killer, check your syslog.

  • What is the command for that?

      • Thanks! It gives me this results:

        Nov 1 07:10:56 www kernel: [4569150.945470] Out of memory: Kill process 18028 (mysqld) score 10 or sacrifice child
        Nov 1 07:10:59 www kernel: [4569154.224945] Out of memory: Kill process 14828 (apache2) score 10 or sacrifice child
        Nov 1 07:11:05 www kernel: [4569160.488419] Out of memory: Kill process 14852 (apache2) score 10 or sacrifice child
        Nov 1 07:11:12 www kernel: [4569166.789485] Out of memory: Kill process 14847 (apache2) score 10 or sacrifice child
        Nov 1 07:11:15 www kernel: [4569170.119728] Out of memory: Kill process 14884 (apache2) score 10 or sacrifice child

        • I've never dealt with this problem so I don't know if this results look normal or something wrong.

        • There you go. You're running out of memory and it's killing mysqld. Upgrade your droplet or use less memory.

I'm receiving some heavy traffic from the same IP (5.8.66.115) :(

5.8.66.115 - - [02/Nov/2015:16:42:44 -0500] "POST /xmlrpc.php HTTP/1.0" 404 463 "-" "Mozilla/4.0 (compatible: MSIE 7.0; Windows NT 6.0)"
5.8.66.115 - - [02/Nov/2015:16:42:45 -0500] "POST /xmlrpc.php HTTP/1.0" 404 463 "-" "Mozilla/4.0 (compatible: MSIE 7.0; Windows NT 6.0)"
5.8.66.115 - - [02/Nov/2015:16:42:46 -0500] "POST /xmlrpc.php HTTP/1.0" 404 463 "-" "Mozilla/4.0 (compatible: MSIE 7.0; Windows NT 6.0)"
5.8.66.115 - - [02/Nov/2015:16:42:47 -0500] "POST /xmlrpc.php HTTP/1.0" 404 463 "-" "Mozilla/4.0 (compatible: MSIE 7.0; Windows NT 6.0)"
5.8.66.115 - - [02/Nov/2015:16:42:49 -0500] "POST /xmlrpc.php HTTP/1.0" 404 463 "-" "Mozilla/4.0 (compatible: MSIE 7.0; Windows NT 6.0)"
5.8.66.115 - - [02/Nov/2015:16:42:49 -0500] "POST /xmlrpc.php HTTP/1.0" 404 463 "-" "Mozilla/4.0 (compatible: MSIE 7.0; Windows NT 6.0)"
5.8.66.115 - - [02/Nov/2015:16:42:49 -0500] "POST /xmlrpc.php HTTP/1.0" 404 463 "-" "Mozilla/4.0 (compatible: MSIE 7.0; Windows NT 6.0)"

Maybe late answer, but you could try to change the value for php fpm in www.conf.

Change:
pm.maxchildren = 100
pm.start
servers = 20

To:
pm.maxchildren = 10
pm.start
servers = 10

This will avoid php to eat your memory when you got more traffic to the site.

Have another answer? Share your knowledge.