MySQL 是否宕掉,如果宕掉则启动

如果你的 MySQL 经常宕机,可以用这个脚本来实现宕机后自动启动,把它加到 crontab 里执行即可。 http://www.codeproject.com/Articles/988967/Mysql-Uptime-Check-Script
#!/bin/bash
 
result=`/usr/bin/mysqladmin ping`
expected='mysqld is alive'
 
if [[ "$result" != "$expected" ]]
then
echo "It's dead - restart mysql"
 
# email subject
SUBJECT="[MYSQL ERROR] - Attempting to restart service"
 
# Email To ?
EMAIL="[email protected]"
 
# Email text/message
EMAILMESSAGE="/tmp/emailmessage.txt"
echo "$result was received"> $EMAILMESSAGE
echo "when we were expected $expected" >>$EMAILMESSAGE
# send an email using /bin/mail
mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
 
sudo /etc/init.d/mysql restart
fi


你可能感兴趣的:(MySQL 是否宕掉,如果宕掉则启动)