Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a rackspace server that I have been renting to run my personal projects upon. Since I am cheap, it has 256Mb of RAM and honestly can't handle alot. Every once in a while, when there is a sharp uptick in traffic, the server decides to start killing processes and it seems that mysqld is a popular one for it to kill. I try to visit my site and am greeted with the message that there was an error establishing the database connection. Inspection of the logs reveals that mysqld was killed due to lack of memory.

Since I am still as poor as I was yesterday and don't want to upgrade my rackspace VM's RAM, is there a way I can tell it to automagically restart mysqld when it dies?

I have a thought to use something like crontab, but alas, I don't know exactly what to do there either. I guess I am product of the "Linux on your desktop" generation since I can do most things on my desktop and laptop (which run Linux almost exclusively), but still lack a lot of server administration skills for Linux.

The server runs CentOS 6.3

share|improve this question
what distro? I think upstart would do this on ubuntu – Journeyman Geek Jun 23 '13 at 23:59
Whoops. Forgot to mention that detail: CentOS – Los Frijoles Jun 24 '13 at 0:16
eh. might want to include the version too – Journeyman Geek Jun 24 '13 at 2:29
Not to detract from the question, but perhaps a long-term solution would be to avoid the condition instead :) If you just want a simple unmanaged VPS for your personal projects, you may be able to pull a good price on a bigger box from a provider that specializes in low end. I have done this with great satisfaction. There are many places to find such VPS providers, e.g. – John Chadwick Jun 24 '13 at 3:10

This is not a clean solution, it would obviously be better to avoid the problem in the first place. Anyway, I am not sure how CentOS manages services but I think it uses service. If so, you can check if the mysql service is running with

/sbin/service mysql status

This command will exit successfully if mysql is running and return a non 0 exit status if i is not. You can therefore start the service if it is not running with this command:

/sbin/service mysql status || service mysql start

You can add this line to /etc/crontab to launch thes command every minute:

* * * * * /sbin/service mysql status || service mysql start
share|improve this answer

This is a little disturbing.

mysqld is always restarted by mysqld_safe because there is an infinite loop in the bottom of mysqld_safe to check for abnormal shutdowns. If the error is too severe, not even mysqld_safe would not be able to restart mysqld on subsequent tries.

Given that situation that mysqld_safe is designed for, it may not be a good idea to force mysqld to start if mysqld_safe will reject it anyway.

You need to locate the error log in my.cnf it will be under




Read the text file (probably by running tail -30 log-filename) and find the source of the mysqld processing shutting down.

share|improve this answer
Interesting...looking at my log it says that mysqld was restarted, but then roughly 1-2 hours later it will say that the process ended. After that the next record is my manual start. Perhaps I have mysqld_safe configured wrong? – Los Frijoles Jun 29 '13 at 5:05

The following is from :

And the culprit is php-fpm! A quick google found another Wordpress customer suffering from similar symptoms; the advice was to tweak the php-fpm pool configuration (/etc/php-fpm.d/www.conf) and tweak the pm configuration. The main change was to move from pm = dynamic to pm = ondemand with a pm.max_children value of 5 (based on observing ~5% memory usage per worker). After changing the configuration I restarted all services and checked the memory usage.

service php-fpm restart
service nginx restart
service mariadb restart

After restarting the memory usage was dramatically lower.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .