修复Mysql主从不同步shell

Posted Travel the world

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了修复Mysql主从不同步shell相关的知识,希望对你有一定的参考价值。

使用第三方工具
mysql Enterprise Monitor,MySQL企业版监控工具。
MONyog – MySQL Monior and Advisor,MONyog大家都不陌生,windows下比较好用的MySQLGUI提供者,也有相关MySQL监控工具。

 

脚本监控
#!/bin/bash


### VARIABLES ###
SERVER=`hostname`
SECONDS_BEHIND_MASTER=`/usr/bin/mysql -e "SHOW SLAVE STATUSG"| grep "Seconds_Behind_Master" | awk -F": " {‘ print $2 ‘}`
SENTFILE_BROKEN=/tmp/mysql_slaverep_broken.sent
SENTFILE_BEHIND=/tmp/mysql_slaverep_behind.sent


### CHECK FOR REPLICATION BREAK ###
if [ "$SECONDS_BEHIND_MASTER" == "NULL" ]; then
# Slave replication is broken

if [ ! -f $SENTFILE_BROKEN ]; then
# This has not been reported before
echo "Slave replication broken on $SERVER"
touch $SENTFILE_BROKEN
fi
else
# Slave replication is not broken

if [ -f $SENTFILE_BROKEN ]; then
# It was broken before which was reported. Clear that state
echo "Slave replication has been restored on $SERVER"
rm $SENTFILE_BROKEN
fi

### CHECK FOR REPLICATION DELAY ###
if [ "$SECONDS_BEHIND_MASTER" -gt "60" ]; then
# Slave replication is delayed

if [ ! -f $SENTFILE_BEHIND ]; then
# This has not been reported before
echo "Slave replication is $SECONDS_BEHIND_MASTER seconds behind master on $SERVER"
touch $SENTFILE_BEHIND
fi
else
# Slave replication is not delayed

if [ -f $SENTFILE_BEHIND ]; then
# It was delayed before which was reported. Clear that state
echo "Slave replication delay has been recovered and is now $SECONDS_BEHIND_MASTER seconds behind master on $SERVER"
rm $SENTFILE_BEHIND
fi
fi

fi

















































以上是关于修复Mysql主从不同步shell的主要内容,如果未能解决你的问题,请参考以下文章

解决MySql主从同步不一致问题

mysql------针对主从同步的情况两个库进行数据校对及恢复

mysql生产环境____主从同步修复案例

如何利用percona-toolkit工具检查MySQL数据库主从一致性以及修复

mysql多线程备份修复主从1062错误

MySQL主从同步报错排错结果及修复过程之:Slave_SQL_Running: No