Question

WordPress "Errorr Establishing Database Connection", but RAM not maxing out?

Posted October 2, 2017 937 views
UbuntuWordPress

I notice that my site will suddenly lose connection the database, and I am getting duplicates of memory allocation errors for MySQL:

/var/log/mysql/error.log:2017-10-02T13:10:21.353353Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log:2017-10-02T15:42:16.056060Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log:2017-10-02T16:55:46.662608Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log:2017-10-02T19:16:24.149783Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log:2017-10-02T19:17:10.792244Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log:2017-10-02T19:51:20.955971Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log:2017-10-02T20:15:03.484067Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log:2017-10-02T20:32:16.391206Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log:2017-10-02T21:27:58.671734Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log:2017-10-02T21:34:31.399781Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log:2017-10-02T21:36:33.327737Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log:2017-10-02T22:27:51.775016Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log.1.gz:2017-10-02T00:49:55.833472Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log.1.gz:2017-10-02T04:10:20.862142Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log.1.gz:2017-10-02T04:26:37.263526Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log.1.gz:2017-10-02T05:51:23.789589Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log.1.gz:2017-10-02T05:52:37.946939Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log.2.gz:2017-09-30T19:15:42.362225Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log.2.gz:2017-09-30T19:52:08.886413Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log.2.gz:2017-09-30T21:29:35.562156Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log.2.gz:2017-09-30T23:45:05.934152Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log.2.gz:2017-09-30T23:46:30.960428Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log.2.gz:2017-10-01T00:17:27.374200Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log.3.gz:2017-09-29T23:32:45.927580Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log.3.gz:2017-09-30T00:01:10.947048Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log.3.gz:2017-09-30T00:08:53.977391Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log.3.gz:2017-09-30T02:47:15.425839Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log.3.gz:2017-09-30T02:47:45.397181Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log.4.gz:2017-09-28T17:20:11.137190Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log.5.gz:2017-09-28T05:17:25.361818Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
/var/log/mysql/error.log.5.gz:2017-09-28T05:35:51.610811Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool

Strangely the DigitalOcean dashboard does not show my memory surpassing ~66%. What is the issue here?

Here’s an image of my dashboard within the past 6 hours:
https://i.imgur.com/aY5aYiC.png

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
2 answers

WordPress had been set only 128MB of RAM in the wp-config.php file. I have mostly fixed the issue by raising it to 256MB, and changed around some mysql.sock settings in the php.ini file (which were missing for some reason).

Hello, all

You will most definitely need to upgrade your droplet as you’re running out of memory and your application/website needs more resources in order to continue to operate.

What you can also do is to use the MySQLTuner script.

The MySQLTuner is a script written in Perl and allows you to quickly test your MySQL configuration and it gives you suggestions for adjustments to increase performance and stability.

According to the official GitHub page, it supports 300 indicators for MySQL/MariaDB/Percona Server in this last version.

To run the script you could do the following:

  • SSH to your Droplet
  • Download the script:
wget http://mysqltuner.pl/ -O mysqltuner.pl
  • Then execute it:
perl mysqltuner.pl

The script would run multiple checks against your MySQL instance, all checks done by MySQLTuner are documented here.

Also as stated in the official documentation, it is still extremely important for you to fully understand each change you make to a MySQL database server. If you don’t understand portions of the script’s output, or if you don’t understand the recommendations, you should consult a knowledgeable DBA or system administrator that you trust.

As a good practice make sure to always test your changes on staging environments before implementing them on your production database.

On the same note, if you want to have a worry-free MySQL hosting and focus on your application, I would recommend trying out the DigitalOcean Managed Databases:

https://www.digitalocean.com/products/managed-databases-mysql/

This was mini tutorial was posted from bobbyiliev in this question in our community: https://www.digitalocean.com/community/questions/how-to-tweak-mysql-mariadb-configuration-for-increased-performance-and-stability

You can also create a simple bash script to check if MySQL is running and if not to restart it.

#!/bin/bash

# Check if MySQL is running
sudo service mysql status > /dev/null 2>&1

# Restart the MySQL service if it's not running.
if [ $? != 0 ]; then
    sudo service mysql restart
fi

Run this script every 5 minutes using a cron job like this one:

 */5 * * * * /home/user/scripts/monitor.sh > /dev/null 2>&1

Hope that this helps!
Regards,
Alex