Mysql server stops very frequently

January 3, 2015 19k views

Recently I installed Zpanel on an Unbuntu 12.04.5 x64 droplet. All gose web, but i have a problem.
Mysql stops working and I have no idea why. Can someone help me with this problem?
I tried to check if mysql is up and make cronjob to restart it but that does not work.
I need to restart manually from command line. That is not a problem, but if i'm not at home, how can i restart the mysql?

  • Did the log file indicate warnings before it died. For mariadb on Ubuntu, do

    tail /var/log/mariadb/mariadb.log

    For mysql on Ubuntu, do

    tail /var/log/mysql/error.log

    Look for shutdown messages or errors.

  • Yeah it's ridiculous. It happens to my site all the time. And I never know when it goes down. No one at digital ocean seems to have any idea why. Definitely considering switching because of it.

  • A power cycle seems to work to load everything back up, but that doesn't work all the time.

  • I am running a couple of low memory instances and it is often an issue with running out of memory. These boxes are running wordpress, which can manage your memory poorly when run out of the box. I have to restart the service:
    sudo service mysql restart
    This is definitely not a fix for the issue, but addresses a symptom. You can add nagios to monitor the server and text you when the database crashes. @monaya

  • Hello, did anyone get a solution for this problem?

  • Hi there,

    I'm facing the same for a while (Wordpress sites too) and always resolve it by a sudo poweroff, but it is really frustrating. To get alerted, I use I definitely need a solution as well.

  • Hi there,

    I'm having the same issue as well. Even when I leave my WP with no traffic at all, the mysql goes down almost everyday or two. I tried to add a swap file to it too but it doesn't help.

  • Hi there,

    I had the problem again (despite increasing -again- droplet size).

    I used /etc/init.d/mysql start and the output was ERROR : The partition with /var/lib/mysql is too full!. Then I used sudo /etc/init.d/mysql start and it did the trick.

    Also you can use sudo service mysql start which is way simpler to remember.
    This is not a fix but at least, this way you don't have to poweroff and restart.

    I will digg around ERROR : The partition with /var/lib/mysql is too full!. Anyone has any idea about it ?

  • I found the solution,
    seems that our droplets doesnt have enogh memory some times and mysql cant allocate what it needs and crash, so we need to create a swap space to help this.
    this is what I did:
    On the command line

    root@myserver:~# dd if=/dev/zero of=/swap.dat bs=1024 count=512k
    root@myserver:~# mkswap /swap.dat
    root@myserver:~# swapon /swap.dat
    root@myserver:~# vim /etc/fstab

    vim is started to edit, add the following to the end of /etc/fstab file

    /swap.dat      none    swap    sw      0       0

    Then, edit the mysql config file

    root@myserver:~# vim /etc/mysql/my.cnf

    And add this under [mysqld]


    Finally reload mysql

    root@myserver:~#  service mysqld reload
  • The solution of Juanjo solves my problem

  • it doesn't solve mine.........

  • The solution of Juanjo solves my problem, too. Thanks!!!!

    Jose Carlos Ramos Carmenates

  • thx juanjo2988
    my sql problem solved!!

  • juanjo2988 soolved my sql problem too! thanks..

5 Answers

This is my error.log:

150103 16:15:26 InnoDB: Completed initialization of buffer pool
150103 16:15:26 InnoDB: highest supported file format is Barracuda.
150103 16:15:26  InnoDB: Waiting for the background threads to start
150103 16:15:27 InnoDB: 5.5.40 started; log sequence number 2230560
150103 16:15:27 [Note] Server hostname (bind-address): ''; port: 3306
150103 16:15:27 [Note]   - '' resolves to '';
150103 16:15:27 [Note] Server socket created on IP: ''.
150103 16:15:27 [Note] Event Scheduler: Loaded 0 events
150103 16:15:27 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.5.40-0ubuntu0.12.04.1'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu)

  • Unfortunately this log looks like you've restarted since the failure. Is that right? Otherwise look for an older timestamped log file to analyze, or you may need to wait till it happens again (with a saved copy of the log saved before restarting mysqld). If this is the logfile before you restarted, then you've got more work to do.

This is my error.log after crash:

root@AdultZone:~# tail /var/log/mysql/error.log
InnoDB: mmap(137363456 bytes) failed; errno 12
150106 18:04:02 InnoDB: Completed initialization of buffer pool
150106 18:04:02 InnoDB: Fatal error: cannot allocate memory for the buffer pool
150106 18:04:02 [ERROR] Plugin 'InnoDB' init function returned error.
150106 18:04:02 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
150106 18:04:02 [ERROR] Unknown/unsupported storage engine: InnoDB
150106 18:04:02 [ERROR] Aborting

150106 18:04:02 [Note] /usr/sbin/mysqld: Shutdown complete

The key error here is:

Fatal error: cannot allocate memory for the buffer pool

This shows that MySql has tried to use more memory than is available. As a result, it is crashing. Adding swap file can give you some flexibility when it comes to memory issues. Check out this tutorial for all the information:

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.
  • I added Swap but same result.
    My droplet is 512MB and i have added a 256 Swap. Is that good or i should increase Swap to 512?

  • @zotacatalin As that tutorial points out, especially on lower memory systems:

    Generally, an amount equal to or double the amount of RAM on your system is a good starting point.

    On my personal 512MB droplets, I always add a 1GB swap file. If that's not enough, you might need to consider scaling up to a larger server. Either way, you should take a closer look at your memory consumption to better understand the problem.

A better solution is to check why your MySQL needs so much memory, try to optimize its resources before you invest on more, use this to optimize: Percona tools. Also check if your site/application/whatever is running smoothly or is causing heavy traffic peaks to your db.

If your mysql and application/website are running on the same droplet maybe you should consider something bigger but again check if is something you can solve before you invest on resources.

use "top" or better yet get a free newrelic account and monitor your server resources so you can be sure which process are consuming memory.

Have another answer? Share your knowledge.