您好(hǎo),歡迎來(lái)到(dào)溫江區帝啓網絡工作室官方網站(zhàn)!ZJ≠Ωα∞JCL.CN
新聞動态
您現(xiàn)在的(de)位置:首頁 > 技(jì)術(shù)文(wén)摘
監控mysql啓動情況并檢測表錯(cuò)誤修複
來(lái)源:創立工(gōng)作(zuò)室 作(zuò≠δ)者:馮軍 發布時(shí)間(jiān):2024-07≤≠∞π-23 11:50:07 閱讀(dú) 1132'♥¥γ 次
#!/bin/env bash
####################↔ ‍​#########################################&÷π##################
# NOγ∞♠TE:
# The test syste₽£♠m is Ubuntu12.04
# This Sc‍α₽±ripts all rights reserved deserve★<d by MickeyZZC
# Copyright  2013
#
#≈♦∞#####################################"πδ############################₩β#############
PATH=/bin:/sbin"←:/usr/bin:/usr/sbin:£☆/usr/local/bin:/usr/local/sbin:€♦~/bin
export PATH
clear
 
u✔φ‍sername=
passwd=
mysqlhקost=""
 
mysqllive(){
    num=0
γ♦¥±
    while [[ `pidof mysqld` == "" ]→↔♣] ; do
        echo "$(date +%Y%m%d%H¥ ₹%m),MYSQL IS DOWN" &gt;&gt; /var/log/✔↔mysqlstat.log
        service mysql start×↔
        num=`expr $num + 1`
     ™•       if [[ $num -gt 11 ]] ; then
            ' ♠    echo "$(date +%Y%m%d%H%m),MYSQL N€$←↔O UP" &gt;&gt; /var/log/mysqls‌δ₹£tat.log
                exit 1§↔÷×
            fi
        sleep 10
    done
 λ₽   if [[ $num -gt 0 ]] ; th'קen
        mysqlsamchk
    ↓¶∏fi
}
mysqlsamchk(){
    if [[ `which my♦≤✔sqlcheck` == "" ]] ;t→​hen
        mysqldata=`mysql -h$mysqlhost -u≈"‌$username -p$passwd -e"sh♦≤≈ow databases"|grep -♥¶vE "mysql|information_sc☆ ¶hema|performance_schema|Database"`
×↑
        for i in ${mysqldata[@]} ; do←βφ→
            mytables=`mysql -h$mysqlhost  ‌♣-u$username -p$passwd -e"use $i;show tables;"|grδ£λ​ep -vE "Tables_in_"`
            for j in Ω¶${mytables[@]} ; do
   π≈φ             table_status=`mysql -h$mysqlhost -uσ"©♣$username -p$passwd -e"check ta★​↕÷ble $i.$j"|awk 'BEGIN{IFS='\t'}{prinβ®πt $3}'|grep "error"`
                if [ ! "  $table_status" == "" ] ; then
             ×★δ       mysql -h$mysqlhost -u$username -p$passwd -≠÷₩e"repair table $i.$j"
                    e♦↕cho "$(date +%Y%m%d%H%M),$i.$j be repair" &am§ ♦p;gt;&gt; /var/log/mysqlstat.logφ®
                fi
 ♣§>            done
        donλ​↑e
    else
        my£¶€sqlcheck --all-databases --auto-repair -u$usernam€±Ω✘e -p$passwd |awk '!/OK/ {pr↔✔≤intf "datetime,%s\n",$1}'|sed "s/dateti&↕>♦me/$(date +%Y%m%d%H%M)/g" &gt®≤<;&gt; /var/log/mysqlstat.log
§✘&
#   day="$(date +%Y%m%d|cut -b 3-8) $(date +%H)∏× "
#   grep "is marked as crashed and should be r<γφ₩epaired" /var/log/mysql.err∞↕
    fi
}
 
if [[ $1 = '≥↔check' ]] ; then
    mysqlsamchk
else
   ∏←®☆ mysqllive
fi