mysql主从配置脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql主从配置脚本相关的知识,希望对你有一定的参考价值。
PASSWD=123456
USER=root
REP_HOST=10.10.10.70
REP_PORT=3306
REP_USER=slave
[email protected]
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主从配置脚本的主要内容,如果未能解决你的问题,请参考以下文章