MySQL crashes but Apache continues

December 9, 2013 10.5k views
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?
8 Answers
"The best way to fix this issue... "

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 $$$?
Apache, alone, consumes a lot of memory. MySQL, particularly on a WordPress site, can 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.

1.) Are you using a 32-bit OS (given that you only have 1 GB of RAM)?

2.) Did you restart both Apache and MySQL after you added swap?

3.) Caching MySQL can also help. See How To Install and Use Memcache on Ubuntu 12.04.

4.) If you're open to making the switch, check out How To Install and Configure Varnish with Apache on Ubuntu 12.04.

I Googled InnoDB: Fatal error: cannot allocate memory for the buffer pool 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).
by Etel Sverdlov
Varnish is an HTTP accelerator and a useful tool for speeding up a server, especially during a times when there is high traffic to a site. It works by redirecting visitors to static pages whenever possible and only drawing on the server itself if there is a need for an active process. This tutorial covers installing wordpress on a LEMP stack (with nginx instead of apache), and then installing varnish.
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.

I had a similar issue before. It seems 1 GB isn't enough for Apache and MySQL running with few wordpress accounts.
Hello Pablo, Logesh K

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.
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

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).

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...

andymc47:

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?


Tunghua

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.

Have another answer? Share your knowledge.