How to monitor and automatically restart mysql?

You can do this with monit. For example, to alert & restart mysql, assuming you run monit on a 60 second cycle:

check process mysqld
  with pidfile /var/run/mysqld.pid
if cpu usage > 99% for 10 cycles then alert
if cpu usage > 99% for 10 cycles then restart

monit is very flexible and can do pretty much any sort of monitoring of processes, memory, etc. you can think of.

This could probably be done with ps-watcher too, but it's hard to make ps-watcher remember this sort of state and act on it. monit is the right tool to use.

Tags:

Mysql

Debian