Wordpress - mysql crash

Posted July 24, 2017 5.6k views
MySQLWordPressUbuntu 16.04

Hello what’s wrong on Digital Ocean?

I have a droplet with 1 GB Memory / 30 GB Disk / AMS2 - Ubuntu 16.04.2 x64 and it work very well in the last 2 months.

Now i want know why in the last 4 days mysql stop working???
i really don’t understand why this occured, i have one more droplet with same specs and more Wordpress site on it, and work very well.

problem is related to ram consuption, but i try a2dissite all my sites and leave just one active, problem persist!!!!!!

tail -40 /var/log/mysql/error.log

2017-07-24T19:04:30.218958Z 0 [Note] InnoDB: Number of pools: 1
2017-07-24T19:04:30.219177Z 0 [Note] InnoDB: Using CPU crc32 instructions
2017-07-24T19:04:30.222532Z 0 [Note] InnoDB: Initializing buffer pool, total siz e = 128M, instances = 1, chunk size = 128M
2017-07-24T19:04:30.222644Z 0 [ERROR] InnoDB: mmap(137428992 bytes) failed; errn o 12
2017-07-24T19:04:30.222824Z 0 [ERROR] InnoDB: Cannot allocate memory for the buf fer pool
2017-07-24T19:04:30.222864Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2017-07-24T19:04:30.222887Z 0 [ERROR] Plugin ‘InnoDB’ init function returned err or.
2017-07-24T19:04:30.222904Z 0 [ERROR] Plugin 'InnoDB’ registration as a STORAGE ENGINE failed.
2017-07-24T19:04:30.222921Z 0 [ERROR] Failed to initialize plugins.
2017-07-24T19:04:30.222935Z 0 [ERROR] Aborting

2017-07-24T19:04:30.222951Z 0 [Note] Binlog end
2017-07-24T19:04:30.223066Z 0 [Note] Shutting down plugin 'MyISAM’
2017-07-24T19:04:30.223766Z 0 [Note] /usr/sbin/mysqld: Shutdown complete

2017-07-24T19:05:00.448335Z 0 [Warning] Changed limits: maxopenfiles: 1024 (re quested 5000)
2017-07-24T19:05:00.448433Z 0 [Warning] Changed limits: tableopencache: 431 (r equested 2000)
2017-07-24T19:05:00.658943Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use –explicitdefaultsfortimestamp server option (see doc umentation for more details).
2017-07-24T19:05:00.662549Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.19-0ubuntu0.16 .04.1) starting as process 5831 …
2017-07-24T19:05:00.672747Z 0 [Note] InnoDB: PUNCH HOLE support available
2017-07-24T19:05:00.672879Z 0 [Note] InnoDB: Mutexes and rw
locks use GCC atomic builtins
2017-07-24T19:05:00.672910Z 0 [Note] InnoDB: Uses event mutexes
2017-07-24T19:05:00.673003Z 0 [Note] InnoDB: GCC builtin _atomicthread_fence() is used for memory barrier
2017-07-24T19:05:00.673107Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.8
2017-07-24T19:05:00.673136Z 0 [Note] InnoDB: Using Linux native AIO
2017-07-24T19:05:00.674193Z 0 [Note] InnoDB: Number of pools: 1
2017-07-24T19:05:00.674524Z 0 [Note] InnoDB: Using CPU crc32 instructions
2017-07-24T19:05:00.677755Z 0 [Note] InnoDB: Initializing buffer pool, total siz e = 128M, instances = 1, chunk size = 128M
2017-07-24T19:05:00.677867Z 0 [ERROR] InnoDB: mmap(137428992 bytes) failed; errn o 12
2017-07-24T19:05:00.677951Z 0 [ERROR] InnoDB: Cannot allocate memory for the buf fer pool
2017-07-24T19:05:00.677980Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2017-07-24T19:05:00.677996Z 0 [ERROR] Plugin 'InnoDB’ init function returned err or.
2017-07-24T19:05:00.678006Z 0 [ERROR] Plugin 'InnoDB’ registration as a STORAGE ENGINE failed.
2017-07-24T19:05:00.678017Z 0 [ERROR] Failed to initialize plugins.
2017-07-24T19:05:00.678025Z 0 [ERROR] Aborting

2017-07-24T19:05:00.678051Z 0 [Note] Binlog end
2017-07-24T19:05:00.678201Z 0 [Note] Shutting down plugin 'MyISAM’
2017-07-24T19:05:00.679034Z 0 [Note] /usr/sbin/mysqld: Shutdown complete

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
5 answers

Hi @ghostpizza

You’re running out of memory, that’s why MySQL is being crashed, so the entire system doesn’t crash.

Are you using CloudFlare? If yes, then make sure it’s not doing offline-cache of your site, since it hammers every page on your site every hour. Otherwise you need to setup cache.

Also make sure you’re not being attacked by having a look in the access log:

# If you're using Apache, then this is the default path
tail -f /var/log/apache2/access.log
# If you're using Nginx, then this is the default path
tail -f /var/log/nginx/access.log
# Press CTRL+C to exit the monitoring
  • hello @hansen thanks for your reply

    Yes i use Cloudflare free account, now i switch it on pause and i know that is a problem regarding out of memory but why now and why for 2 months all worked well!

    i start command you suggested, but how i can recognize attack?

    • @ghostpizza

      I don’t know if CloudFlare maybe changed something in their offline-cache - maybe it’s hitting the server much more. You have to ask them.

      Or it could be a plugin/theme update, which is doing heavier/longer queries.

      You can see if there are many requests per second going to the same URL (usually someone trying to brute-force the login to gain access) or if the amount of many requests doesn’t correlate with your amount of visitors (that could be the CloudFlare offline-cache or a bad search engine web-crawler).

i am very frustating, here you can see graph of my droplet, memory drop down just after droplet shutdown - r :

I had memory issues with my droplet hosting just a couple of WordPress sites with very low traffic.

However, I added the following to my apache2.conf:

<files xmlrpc.php>
        order allow,deny
        deny from all

My issues with MariaDB running out of RAM seem to have disappeared after doing this, so I suspect it could have been an XML RPC attack against WordPress.

Hello, all

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


# 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

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

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

Hope that this helps!

Hello, all

The key error here is:

InnoDB: Fatal error: cannot allocate memory for the buffer pool

This crash is due to your system running out of memory. I’d suggest that you add a swap file to give yourself a bit more of a buffer. Check out this tutorial:

How To Add Swap on Ubuntu 14.04

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 -O
  • Then execute it:

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:

This was mini tutorial was posted from @bobbyiliev in this question in our community:

Hope that this helps!

by Justin Ellingwood
Swap space can be used as an "overflow" area for your system when you run out of RAM. The operating system can store data that would normally be kept in RAM on the hard drive in a specially formatted file. In this guide, we'll demonstrate how to create and use one of these files in Ubuntu 14.04.