Skip to content

Instantly share code, notes, and snippets.

@sageworksstudio
Last active May 15, 2021 18:24
Show Gist options
  • Select an option

  • Save sageworksstudio/c15e361cc0b9aa0a5ae1b17e270a9ae4 to your computer and use it in GitHub Desktop.

Select an option

Save sageworksstudio/c15e361cc0b9aa0a5ae1b17e270a9ae4 to your computer and use it in GitHub Desktop.
Restart MySQL

Restart MySQL

Create a file that root/sudo can access:

restart-mysql.sh:

#!/bin/bash
PATH=/usr/sbin:/usr/bin:/sbin:/bin
if [[ "$(service mysql status)" != "running" ]]
then
  service mysql start
fi

Make the file executable: chmod +x restart-mysql.sh

Then set to your crobtab to run the script every 5 minutes.

sudo crontab -e

First, add MAILTO="" to the top of the cron script. It will disable a lot of annoying emails. Or add your email if you prefer to receive an email when the script runs.

Then add to the bottom of the crontab script:

m h dom mon dow command

*/5  *  *  *  * /path/to/restart-mysql.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment