Thursday, June 24, 2010

Check Mysql Master-Slave Replication Script.

This is Mysql Master-Slave Replication Script which is checking position of log. you can set as cron and run.

vi /usr/bin/scriptname

#! /bin/bash
#
# Will Run on LOCAL LAN ON EC2 CLUSTER

SLAVE_HOST=1.2.2.1
SLAVE_PASS=passwd
SLAVE_USER=root

MASTER_PASS=passwd
MASTER_USER=root
MASTER_HOST=1.2.4.2

master_pos=`/usr/local/mysql/bin/mysql -u$SLAVE_USER -p$SLAVE_PASS -h$SLAVE_HOST -e 'show slave status \G;' |grep -r 'Read_Master_Log_Pos' |awk '{ printf " %s ", $2 }' |xargs`


slave_pos=`/usr/local/mysql/bin/mysql -u$MASTER_USER -p$MASTER_PASS -h$MASTER_HOST -e 'show master status;' | grep mysql-bin |awk '{ printf " %s ", $2 }' |xargs`

echo $master_pos
echo $slave_pos

expr $master_pos - $slave_pos

echo $master_pos
echo $slave_pos

1 comments:

Renu said...

Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
Devops Training in electronic city