For some reason, MySQL goes down very often.

I would like to learn how to make a script that would check If MySQL is down and if so then start it again using service mysql start.

Any suggestions?

  • 1
    How about finding out why MySQL is going down? look in /var/lib/mysql/*.err for details .
    – thinice
    Dec 7 '11 at 3:35

install and use monit


You can monitor the mysql process and if it is down monit can restart it for you.. a sample config might look like

check process mysql with pidfile /var/run/mysqld/mysqld.pid
   group database
   start program = "service mysql start"
   stop program = "service mysql stop"
   if failed host port 3306 protocol mysql then restart
   if 5 restarts within 5 cycles then timeout

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.