1, according to MySQL Port 3306来 Judge service start is not normal
Netstat-lnt|grep 3306|awk-f ' [:]+ ' {print $} '//Get the port number comparison to determine
#!/bin/shportnum= ' Netstat-lnt|grep 3306|awk-f ' [:]+ ' {print $} ' if ["$PortNum" = = 3306];then echo "DB is running" Else/data/3306/mysql Restartfi
Netstat-lnt|grep 3306|wc-l//result equals 1, database is running normally, result equals 0, database is not running properly
#!/bin/sh
portnum= ' Netstat-lnt|grep 3306|wc-l ' if [$PortNum-eq 1];then echo "DB is running" Else/data/3306/mysql Restartfi
2, if MySQL port and process exist at the same time, the MySQL service is considered normal
Ps-ef|grep mysql|grep-v grep|wc-l//Convert the process to the number of rows to make it easy to judge: The normal START process number is 2
#!/bin/shportnum= ' netstat-lnt|grep 3306|wc-l ' mysqlprocessnum= ' ps-ef|grep mysqld|grep-v grep|wc-l '//if [$PortNum-eq 1] && [$mysqlProcessNum-eq 2];thenif [$PortNum-eq 1-a $mysqlProcessNum-eq 2];then echo "DB is running" E Lse/data/3306/mysql Startfi
#!/bin/shmysqlprocessnum= ' ps -ef|grep mysqld|grep -v grep|wc -l ' PortNum= ' netstat -lnt|grep 3306|wc -l ' mysqlstartup= "/data/3306/mysql" logpath= "/tmp/mysql.log" if [ $ portnum -eq 1 -a $mysqlProcessNum -eq 2 ];then echo "db is running "else $MysqlStartUp start > $LogPathsleep 10; mysqlprocessnum= ' ps -ef|grep mysqld|grep -v grep|wc -l ' PortNum= ' netstat -lnt|grep 3306|wc -l ' if [ $PortNum -ne 1 ] && [ $mysqlProcessNum -ne 2 ];then while true do killall mysqld >/dev/null 2>&1 [ $? -ne 0 ] && break sleep 1 done $MysqlStartUp start >> $LogPath && status= "Successfully" | | Status= "Failure" [ $PortNum -eq 0 ] && $ mysqlstartup start >>/tmp/mysql.log [ $? -eq 0 ] & & echo "mysql is started" fi mail -s "MySQL startup status is $status " [email protected] < $LOGPATHFI
Analog Landing judgment:
Mysql-uroot-p ' 123456 '-s/data/3306/mysql.sock-e "select version ();" >/dev/null 2>&1
#!/bin/shmysqlstatus= ' mysql-uroot-p ' 123456 '-s/data/3306/mysql.sock-e ' select version (); ">/dev/null 2>&1 ' If [$?-eq 0];then echo "DB is running" Else/data/3306/mysql Restartfi
MySQL detection script