How to automatically restart MySQL service

Published by Igor Khrupin on

Here is instruction how to launch MySQL server after close unexpectedly.

1. Create /root/ file with next content:

if [[ ! "$(/usr/sbin/service mysql status)" =~ "active (running)" ]]
    echo $(date -u) "MySQL service on the server has been stopped. It has now been restarted."
    sudo service mysql start

2. Make it executable `chmod +x /root/`
3. `sudo crontab -e`
4. Add crontab job. For 3 min period job will be next:

*/3 * * * * /root/ >> /var/log/mysqlfix.log 2>&1

/var/log/mysqlfix.log – log file

Let me know better approach in comments.


Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.