Cron job to keep MySQL Running

If your MySQL server is randomly falling over, you need to fix it. There’s no good reason to let that nonsense continue. Sometimes though, that’s easier said than done and whilst you’re working on why the server keeps falling over you need something to keep bringing it back up

Here’s a little snippet of code that will do just that. Call it from a CRON job and your server will be checked and started back up as regularly as you need it to be.

systemctl is-active --quiet mysql || systemctl restart mysql

Leave a Reply