前往顾页
以后地位: 主页 > 收集编程 > Php实例教程 >

查抄MySQL的Slave是不是一般的法度代码

时候:2010-11-06 00:19来源:知行网www.zhixing123.cn 编辑:麦田守望者

下午写了一个的查抄MySQL REPLICATION的SLAVE是不是一般的脚本,比较简朴。
如果想和CRONTAB一块运行,去失落Read部分便可。
1、脚本1经由过程MYSQL 号令 show status 来检察
[root@localhost ~]# 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、测试一下


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

我停失落SLAVE。
[root@localhost ~]# cat /var/log/mysql_slave.log
Slave is not running!

 

------分开线----------------------------
标签(Tag):MYSQL 数据库 MySQL教程 Mysql5
------分开线----------------------------
保举内容
猜你感兴趣