简单的MYSQL检测

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

# !bin/bash
MYSQLPID='/var/run/mysqld/mysqld.pid';

if [ ! -f $MYSQLPID ] ; then
    service mysqld start &>> mysql.error.log;

    if [ $? -ne 0 ] ; then
        for i in $(ps -ef|grep mysqld | grep -v grep | awk '{print $2}')
        do
            kill -9 $i;
        done

        service mysqld start &>> mysql.error.log;
    fi   
    exit;
fi
             
PID=$(tail $MYSQLPID); 

if [[ X$PID -eq X ]] ; then
    rm -rf $MYSQLPID;
    
    if [ $? -eq 0 ] ; then 
        for i in $(ps -ef|grep mysqld | grep -v grep| awk '{print $2}')
        do
            kill -9 $i;
        done
    
        service mysqld stop  &>> mysql.error.log;
        service mysqld start &>> mysql.error.log;
    else
        echo "MYSQL PID 文件删除失败. " 1>> mysql.error.log
    fi
fi