Question

MySQL crashes but Apache continues

  • Posted December 9, 2013

Hello

I have recently moved one of my moderately active sites to a new Digital ocean droplet. Its wordpress with PHP and MySQL on a 1gb Droplet.

After a few hours of the system running, the MySQL server would stop responding. I restarted the system to get the MySQL database back up and running “sudo shutdown -r 0” and it would continue for a few more hours before crashing again.

First thing I tried was adding a 1gb swap file https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-12-04 This did not resolve the issue and I continued to have the same issue.

I looked in the MySQL log file and found the following errors

131206 20:21:47 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead. 131206 20:21:47 [Note] Plugin ‘FEDERATED’ is disabled. 131206 20:21:47 InnoDB: The InnoDB memory heap is disabled 131206 20:21:47 InnoDB: Mutexes and rw_locks use GCC atomic builtins 131206 20:21:47 InnoDB: Compressed tables use zlib 1.2.3.4 131206 20:21:47 InnoDB: Initializing buffer pool, size = 128.0M InnoDB: mmap(135987200 bytes) failed; errno 12 131206 20:21:47 InnoDB: Completed initialization of buffer pool 131206 20:21:47 InnoDB: Fatal error: cannot allocate memory for the buffer pool 131206 20:21:47 [ERROR] Plugin ‘InnoDB’ init function returned error. 131206 20:21:47 [ERROR] Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed. 131206 20:21:47 [ERROR] Unknown/unsupported storage engine: InnoDB 131206 20:21:47 [ERROR] Aborting 131206 20:21:47 [Note] /usr/sbin/mysqld: Shutdown complete

131206 20:21:48 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead. 131206 20:21:48 [Note] Plugin ‘FEDERATED’ is disabled. 131206 20:21:49 InnoDB: The InnoDB memory heap is disabled 131206 20:21:49 InnoDB: Mutexes and rw_locks use GCC atomic builtins 131206 20:21:49 InnoDB: Compressed tables use zlib 1.2.3.4 131206 20:21:49 InnoDB: Initializing buffer pool, size = 128.0M InnoDB: mmap(135987200 bytes) failed; errno 12 131206 20:21:49 InnoDB: Completed initialization of buffer pool 131206 20:21:49 InnoDB: Fatal error: cannot allocate memory for the buffer pool 131206 20:21:49 [ERROR] Plugin ‘InnoDB’ init function returned error. 131206 20:21:49 [ERROR] Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed. 131206 20:21:49 [ERROR] Unknown/unsupported storage engine: InnoDB 131206 20:21:49 [ERROR] Aborting 131206 20:21:49 [Note] /usr/sbin/mysqld: Shutdown complete 131207 0:03:09 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.

This line: " 131206 20:21:47 InnoDB: Fatal error: cannot allocate memory for the buffer pool " Makes it sound like I am currently running out of ram. So I am assuming that its a ram issue.

Next I installed sysstats at the suggestion of a friend, Its currently running every 10mins to hopefully tell me what is happening just before a crash.

I’m not sure what else to try at this point.

Any suggestions?

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

<b>"The best way to fix this issue… "</b> <br> <br>Wouldn’t the “best way” be to follow WordPress best-practices and use Nginx? Why pay more $$$ for a larger droplet to handle Apache, when one can achieve better performance with Nginx for less $$$?

Hello, all

The key error here is:

140707 23:37:13 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 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

Hope that this helps! Regards, Alex

I’m having this error as well with wordpress + fedora 20. I upgraded from the $5 plan to the $20 plan and it’s still happening. Not sure what to do from here.

andymc47: <br> <br> I have exactly the same problem, and thinking to migrate to nginx too, but I have tried and I find that nginx can not unable wordpress permlink, this is a big problem for me, I wonder how do you solve that? <br> <br> <br>Tunghua

I’ve been having the same problem, where I’d routinely have to restart MySQL. I was running two low-traffic WordPress sites on a LAMP server along with a PPTP VPN Server on a 500 MB Droplet <br> <br>I installed Swap, but still, if I hit my site and held down Ctrl-F5 then the server’s memory would goe up and up and up until MySQL crashed. And with Swap installed, the performance drops off before MySQL crashes (although it stays up longer). <br> <br>So anyway, I decided to give Nginx a go. It turned out pretty easy to migrate and now when I hold Ctrl-F5, the server’s memory holds stable at around 330 MB (with Apache running and no load it was around 480 MB and it went up with traffic). I only migrated tonight, but it’s looking good so far… <br> <br>

Hello Pablo, Logesh K <br> <br>I created a snapshot of my old droplet and created a new larger (2gb ram) droplet. Then I replaced Apache with Nginx, added Varnish. I plan to look in to Memcached tonight to see if it will help.

The best way to fix this issue is by Fast Resize or take a snapshot of the Droplet and create a new 2 GB Droplet with the Snapshot which can fix the issue. <br> <br>I had a similar issue before. It seems 1 GB isn’t enough for Apache and MySQL running with few wordpress accounts.

Apache, alone, consumes a lot of memory. MySQL, particularly on a WordPress site, <i>can</i> use up a lot of memory (especially if you have a lot of dynamic content on your site). Mix those two ingredients together and, well, that’s – in all likelihood – the problem you’re encountering. Because of this, WordPress.com (the people that invented WordPress) and ALL of the “premium” WordPress-hosting providers, dumped Apache in favor of Nginx years ago. <br> <br>1.) Are you using a 32-bit OS (given that you only have 1 GB of RAM)? <br> <br>2.) Did you restart both Apache and MySQL after you added swap? <br> <br>3.) Caching MySQL can also help. <i>See</i> <a href=“https://www.digitalocean.com/community/articles/how-to-install-and-use-memcache-on-ubuntu-12-04”>How To Install and Use Memcache on Ubuntu 12.04</a>. <br> <br>4.) If you’re open to making the switch, check out <a href=“https://www.digitalocean.com/community/articles/how-to-install-wordpress-nginx-php-and-varnish-on-ubuntu-12-04”>How To Install and Configure Varnish with Apache on Ubuntu 12.04</a>. <br> <br>I Googled <code>InnoDB: Fatal error: cannot allocate memory for the buffer pool</code> and it looks like a lot of users experienced the same thing as you with WordPress installations on Amazon EC2 micro-instances (and even some on instances w/1 GB of RAM).