The Random Thoughts of a Geek heading for Banbury
The Random Thoughts of a Geek heading for Banbury

restart MySQL if it dies

Because MySQL is sometimes a crazy pain in the arse, and will kill itself every once in awhile without warning, and apparently without any meaningful reason, (I only know it has happened when I get a SMS from my uptime monitor), I have been looking into a better way of managing it than SSHing into the box and running service mysql restart,

This is not a clean solution! it would obviously be better to avoid the problem in the first place. Anyway. If so, you can check if the mysql service is running with service mysql status

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

You can add a file to  line to /etc/cron.d/ called mysql to launch this command every minute:

* * * * * service mysql status || service mysql start

Leave a comment

Your email address will not be published.

One thought on “restart MySQL if it dies”