How to automatically restart MySQL service
Here is instruction how to launch MySQL server after close unexpectedly.
1. Create /root/mysqlfix.sh file with next content:
#!/bin/bash PATH=/usr/sbin:/usr/bin:/sbin:/bin if [[ ! "$(/usr/sbin/service mysql status)" =~ "active (running)" ]] then echo $(date -u) "MySQL service on the server has been stopped. It has now been restarted." sudo service mysql start fi
2. Make it executable `chmod +x /root/mysqlfix.sh`
3. `sudo crontab -e`
4. Add crontab job. For 3 min period job will be next:
*/3 * * * * /root/mysqlfix.sh >> /var/log/mysqlfix.log 2>&1
/var/log/mysqlfix.log – log file
Let me know better approach in comments.
0 Comments