返回首頁
當前位置: 主頁 > 網絡編程 > Php實例教程 >

檢查MySQL的Slave是否正常的程序代碼

時間:2010-11-06 00:19來源:知行網www.wtckvq.live 編輯:麥田守望者

下午寫了一個的檢查MySQL REPLICATION的SLAVE是否正常的腳本,比較簡單。
如果想和CRONTAB一塊運行,去掉Read部分即可。
1、腳本1通過MYSQL 命令 show status 來查看
[[email protected] ~]# cat slave_is_running

#!/bin/sh

#

# Created by david yeung

#

# To determine whether slave is running or not.

echo "Enter your Username"
read USERNAME
echo "Enter your password"
stty -echo
read PASSWD
stty echo
cd /usr/local/mysql/bin

RESULT=`./mysql -u$USERNAME -p$PASSWD -e 'show status like "Slave_running"' -ss | awk '{print $2}'`
if [ "$RESULT" == 'ON' ]
then
echo "Slave is running!" > /var/log/mysql_slave.log
else
echo "Slave is not running!"> /var/log/mysql_slave.log
fi

2、腳本2通過MYSQL命令 show slave status\G來實現


#!/bin/sh

#

# Created by david yeung

#

# To determine whether slave is running or not.

echo "Enter your Username"
read USERNAME
echo "Enter your password"
stty -echo
read PASSWD
stty echo
cd /usr/local/mysql/bin

RESULT=`./mysql -u$USERNAME -p$PASSWD -e 'show slave status\G' -ss| awk '{print $2}' | head -n 13 | tail -n2`
if [ "$RESULT" == 'Yes Yes' ]
then
echo "Slave is running!" > /var/log/mysql_slave.log
else
echo "Slave is not running!"> /var/log/mysql_slave.log
fi

3、測試一下


[[email protected] ~]# ./slave_is_running
Enter your Username
root
Enter your password
[[email protected] ~]# cat /var/log/mysql_slave.log
Slave is running!

我停掉SLAVE。
[[email protected] ~]# cat /var/log/mysql_slave.log
Slave is not running!

 

------分隔線----------------------------
標簽(Tag):數據庫 MYSQL MySQL教程 Mysql5
------分隔線----------------------------
推薦內容
猜你感興趣
深蓝海域APP