Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4184002
  • 博文数量: 240
  • 博客积分: 11504
  • 博客等级: 上将
  • 技术积分: 4277
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-28 14:24
文章分类

全部博文(240)

分类: Mysql/postgreSQL

2008-06-27 17:56:33

下午写了一个的检查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!

阅读(6244) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

justinyun2008-09-04 11:14:03

请问一下,slave在什么情况下,会是mysqld服务没停掉,而本身停掉!