Home  >  Article  >  Database  >  A simple MYSQL detection example code

A simple MYSQL detection example code

零下一度
零下一度Original
2017-04-25 16:01:33993browse

学习shell编程,做了一个检测MYSQL时候启动的脚本,刚学SHELL没几天,欢迎大家给意见和建议

# !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

The above is the detailed content of A simple MYSQL detection example code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn