mysql service stops automatically


The most common reason why MySQL is not running is that it stopped or failed to start as a result of not enough memory.

This can usually be seen by attempting to start the mysql server (“service mysql start” on Ubuntu and some other systems) and then reviewing the mysql error log (usually in /var/log/mysql/error.log or similar file path).

A useful program to review the logs one page at a time is “less” –for example:

less /var/log/mysql/error.log

If you see memory issues such as “mmap can’t allocate” then you can be sure that you are having memory issues.

Potential solutions are:

1) Optimizing MySQL with mysqltuner.
On your server there is a file: /etc/mysql/my.cnf that sets the basic configuration settings of your MySQL service. It controls how much RAM MySQL will try to use, and in what way. The MySQLtuner utility takes a look at certain log files and other information regarding how your MySQL server is functioning and gives you a diagnosis on how efficiently it is performing. At the bottom will be a list of configuration changes you can make to your config file. The longer your server has been running before using MySQLtuner, the more accurate the information it gives you will be.

2) Resize up to a larger droplet.
We recommend at minimum a 1GB droplet for any server utilizing a MySQL database, but the size and type of data stored can significantly affect memory requirements.

3) Reduce your web application’s reliance on MySQL for page loads (if you are running a web server).
This can usually be done by adding static caching to your application. For example, Joomla has caching as a built in feature that can be enabled. Another example, WordPress can use plugins (like WP Super Cache) to add in this kind of functionality.

If you see other errors in the log file that aren’t related to OOM, you can send the log over using something like and I’ll take a look to see if I can figure out what is going on.  🙂