Shell script to restart MySQL automatically when it shuts down.

A dirty hack but essential at times, MySQL server consumes higher memory if not configured correctly and due to which the MySQL service is terminated by the OS to save itself from crashing under high traffic.

A simple shell script can be used to restart MySQL service when it terminated.

Download this script using wget

[code lang=”shell”]wget https://gist.githubusercontent.com/Nikschavan/2346941b328b2c7f08b79611b2c9157c/raw/75ccc4855a2e8955d1c9ffac430857704f8c15f4/mysql-monitor.sh[/code]

Make the script executable
[code lang=”shell”]sudo chmod +x mysql-monitor.sh[/code]

Execute this script each minute with a crontab
[code lang=”shell”]sudo crontab -e[/code]
[code lang=”shell”]*/1 * * * * sh /path/to/script/mysql-monitor.sh[/code]

Leave a Reply

%d bloggers like this: