How do you check MySql status via cron
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.×
A question can only have one accepted answer. Are you sure you want to replace the current answer with this one?
You previously marked this answer as accepted. Are you sure you want to unaccept it?
How about this in your /etc/crontab
# Restart MySQL if it's down * * * * * root service mysql status || service mysql start
You can create a simple bash script to check if MySQL is running and if not to restart it.
#!/bin/bash # Check if MySQL is running sudo service mysql status > /dev/null 2>&1 # Restart the MySQL service if it's not running. if [ $? != 0 ]; then sudo service mysql restart fi
Run this script every 5 minutes using a cron job like this one:
*/5 * * * * /home/user/scripts/monitor.sh > /dev/null 2>&1
Hope that this helps!