MySQL detection script

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.