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主从配置脚本的主要内容,如果未能解决你的问题,请参考以下文章

zabbix监控Mysql主从状态

mysql主从配置脚本

CentOS 7 MySQL5.7 主从配置-binlog 新服务器从安装mysql到主从配置完成只需要3分钟

监控MYSQL主从同步配置中监控从库运行状态的脚本

zabbix监控mysql主从状态

脚本分享-MYSQL服务+主从+告警通知监控