There are several ways to solve the problem of Apache running wild and killing MySQL. It the problem occurs very infrequently, there’s a easy way of restarting MySQL with the use of the crontab. The script even sends a notification email so you know what just happened.
First, SSH into your server:
Create a script file:
Paste the following:
|
#!/bin/bash PATH=/usr/sbin:/usr/bin:/sbin:/bin if [[ ! "$(/usr/sbin/service mysql status)" =~ "start/running" ]] then echo "MySQL restarted for henriksson.me on Digital Ocean" | mail -s "MySQL restarted" markus@henriksson.me sudo service mysql start fi |
Press CTRL + O to save, and CTRL + X to exit.
Give execute permission to your script:
Edit the Crontab:
Paste the following:
|
* * * * * /root/mysqlfix.sh |
Press CTRL + O to save, and CTRL + X to exit.
To see if it works, type the following:
In case the service doesn’t start, just start it manually with the following: