码迷,mamicode.com
首页 > 数据库 > 详细

mysql主从配置脚本

时间:2016-08-31 22:07:20      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:

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

mysql主从配置脚本

标签:

原文地址:http://www.cnblogs.com/fanxuanhui/p/5827375.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!