Sometimes MySQL crash for various reasons (out of memory), there is a simple hack to make sure MySQL running.
Save this to dbcheck.sh
1 2 3 4 5 6 7 8 9 10 11 | #!/bin/bash PIDOF=/usr/sbin/pidof SERVICE=/usr/sbin/service if [[ ! `$PIDOF -s mysqld` ]]; then $SERVICE mysqld restart # can be mysql or mariadb echo "DB restarted" else echo "DB is healthy" fi |
Make it executable by chmod +x dbcheck.sh , and setup a cronjob as root for it to run periodically (e.g. every minute)
1 | * * * * * /home/jason/dbcheck.sh > /dev/null |
Note that this is not considered a good practice, you should find out what is crashing the DB/service, but it is a simple hack to save your some time.