Error establishing a database connection (WordPress) in Help

edited September 2015 in Help
Server 512 RAM
Visitors per day : ~200

-------------------------------
Hi there, I'm having a really hard time figuring this out...

My website shows up "Error establishing a database connection" on occasion. This happens about once a day. As soon as I reboot the droplet, the problem's gone. I've tried adding the following 2 lines in my wp-config file, as suggested on some other forums, but it didn't work:

define('WP_MEMORY_LIMIT', '500M');

From what I read around the web, it seems that 512mb of RAM is perfectly fine for a wordpress multisite, if set correctly - though I'm having a hard time with a single (low content) site, without many plugins. I've also disabled/deleted the plugins that could potentially eat up a lot of memory, such as wp-backup.

There is a solution ?

I don't see something wrong in the mysql error log : http://pastebin.com/QbjY1Dm5

Thanks for you help.
Otherwise, i need to move to an other hosting :(
Tagged:

Comments

  • Are you using the one-click Vultr app for WordPress?

    If so, I'd recommend checking the "php-fpm" error log. That may give you a better clue as to why the connection is failing.

    The path is: /var/log/php-fpm/www-error.log
  • Hi,
    Yes, i'm using the one-click Vultr app for Wordpress
    For the php-fpm error log, not other clue (http://pastebin.com/KaaMK97a)
    Any idea ?

    Note : the pastebin is from the log : /var/log/php-fpm/error.log (no www-error.log, i don't find this file)

  • I have run into this a couple of times before. It usually happens when the database (MySQL in my case) crashes. It's typically a sign that the database has run out of memory, either due to multiple queries being run at the same time, or a malicious query taking up too much RAM.

    There are a few things I've found that will work around the problem:

    1. Free up some RAM or upgrade the VPS to have more RAM, around 1GB or so should work.

    2. Create a cron job in /etc/crontab which checks on the status on the database and restarts it if the process dies. Have the job run every few minutes. If your site runs into heavy traffic, the cron job will restart the database and connections to Wordpress will work again.
  • Locate and run the mysqltuner script (http://mysqltuner.com/) it shows lots of handy info including various memory and connection usages (that often catches people out with its default of ~100 connection limit).
  • Hi, thanks for the help
    I'm trying the second option with the cron job with this script.
    Here the script if someone need : https://github.com/sierracircle/services-checker

    I'll check the next days how it's going on
  • In addition to the recommendations above, you could try tweaking the following variables in the "/etc/my.cnf" file.

    innodb_buffer_pool_size
    table_open_cache

    I haven't tried the mysqltuner script recommended by ac000 - but that may tweak these for you. The version of MySQL used by the WordPress app has InnoDB enabled, which is a memory-hungry engine.
  • Thanks, will try this too
  • @maul

    IIRC it doesn't do the tweaking for you, but it does give you recommendations.
  • Hi,
    A last help please.
    I tried to setup to lanch a cron job every 2 minutes
    what is the path of the mysql for vultr (because this path doesn't work)
    thanks !

    if [[ ! "$(/usr/sbin/service mysql status)" =~ "start/running" ]]
  • Hi,
    it's fine, i solve my problem with this script (working good in vultr server)
    http://www.joe0.com/2011/04/06/cron-script-to-restart-apachemysql-centosrhel/

    here the linux commands to "play" with the start/stop/restart for apache and mysql
    http://mixeduperic.com/centos/how-to-start-stop-restart-and-check-the-status-apache-and-mysql-on-centos.html

    Now, it's working like a charm
  • edited October 2015
    You can also try to rebuild Nginx PHP-FPM MariaDB, etc with VPSSIM bash script. It comes with an option to auto restart mysql.

    https://vpssim.com/250-use-auto-re-start-mysql-server-function.html
  • edited July 2017
    So it happened to me basically overnight. At the end, I ran:

    /etc/init.d/mysqld status

    from this site (also mentioned above):

    http://mixeduperic.com/centos/how-to-start-stop-restart-and-check-the-status-apache-and-mysql-on-centos.html

    Turned out that mysql was stopped! How that happened remains a mystery since I did not change anything. The solution was to simply run:

    /etc/init.d/mysqld start

Sign In or Register to comment.