Skip to content

Instantly share code, notes, and snippets.

@Nikschavan
Created December 20, 2016 10:00
Show Gist options
  • Save Nikschavan/2346941b328b2c7f08b79611b2c9157c to your computer and use it in GitHub Desktop.
Save Nikschavan/2346941b328b2c7f08b79611b2c9157c to your computer and use it in GitHub Desktop.
Shell script to restart MySQL automatically when it shuts down
#!/bin/bash
UP=$(pgrep mysql | wc -l);
if [ "$UP" -ne 1 ];
then
echo "MySQL is down.";
sudo service mysql start
fi
@Nikschavan
Copy link
Author

Nikschavan commented Dec 20, 2016

Download the script with wget

wget https://gist.githubusercontent.com/Nikschavan/2346941b328b2c7f08b79611b2c9157c/raw/75ccc4855a2e8955d1c9ffac430857704f8c15f4/mysql-monitor.sh

Make the script executable

sudo chmod +x mysql-monitor.sh

Execute this script each minute with a crontab

sudo crontab -e

*/1 * * * * sh /path/to/script/mysql-monitor.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment