Home > Database > Mysql Tutorial > A simple MYSQL detection example code

A simple MYSQL detection example code

零下一度
Release: 2017-04-25 16:01:33
Original
1059 people have browsed it

学习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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template