PASSWD=123456

USER=root

REP_HOST=10.10.10.70

REP_PORT=3306

REP_USER=slave

REP_PASSWD=123456@

REP_FILE=mysql-bin.000021

REP_POS=863718

if [ ! -f /var/lock/mysql-zc.lock ];then

mysql -u$USER -p$PASSWD -e “change master to master_host=’$REP_HOST’, master_port=$REP_PORT, master_user=’$REP_USER’, master_password=’$REP_PASSWD’, master_log_file=’$REP_FILE’, master_log_pos=$REP_POS;”

touch /var/lock/mysql-zc.lock

fi

start(){

if [ ! -f /var/lock/mysql-start.lock ];then

mysql -u$USER -p$PASSWD -e “start slave;”

sleep 1

mysql -u$USER -p$PASSWD -e “show slave status\G;”|grep -E “Slave_SQL_Running|Slave_IO_Running”

touch /var/lock/mysql-start.lock

[ -f /var/lock/mysql-stop.lock ]&&rm -rf /var/lock/mysql-stop.lock

else

echo “slave is start!!!”

fi

}

stop(){

if [ ! -f /var/lock/mysql-stop.lock ];then

mysql -u$USER -p$PASSWD -e “stop slave;”

mysql -u$USER -p$PASSWD -e “show slave status\G;”|grep -E “Slave_SQL_Running|Slave_IO_Running”

touch /var/lock/mysql-stop.lock

[ -f /var/lock/mysql-start.lock ]&&rm -rf /var/lock/mysql-start.lock

else

echo “slave is stop!!!”

fi

}

case “$1” in

start)

start

;;

stop)

stop

;;

status)

mysql -u$USER -p$PASSWD -e “show slave status\G;”|grep -E “Slave_SQL_Running|Slave_IO_Running”

;;

*)

echo “usage : start| stop|status”

;;

esac

发表回复

您的电子邮箱地址不会被公开。