MySQL复制状态检查脚本
Posted wzy0623
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL复制状态检查脚本相关的知识,希望对你有一定的参考价值。
sql_slave_skip_1.sh
#!/bin/bash
source ~/.bashrc
Slave_IO_Running_S=$(mysql -uroot -p123456 -S /data1/3306/mysqldata/mysql.sock -e "show slave status\\G" | grep -Po '(?<=Slave_IO_Running: )(?:.*)')
Slave_SQL_Running_S=$(mysql -uroot -p123456 -S /data1/3306/mysqldata/mysql.sock -e "show slave status\\G" | grep -Po '(?<=Slave_SQL_Running: )(?:.*)')
[ -z "$Slave_IO_Running_S" -o -z "$Slave_SQL_Running_S" ] && continue
[[ $Slave_IO_Running_S == "Yes" ]] && S1=1 || S1=0
[[ $Slave_SQL_Running_S == "Yes" ]] && S2=1 || S2=0
if [[ $S1 == 0 ]] || [[ $S2 == 0 ]];then
Last_SQL_Error_S="$(mysql -uroot -p123456 -S /data1/3306/mysqldata/mysql.sock -e "show slave status\\G" | grep Last_SQL_Error)"
mysql -uroot -p123456 -S /data1/3306/mysqldata/mysql.sock -e "stop slave;set global sql_slave_skip_counter=1;start slave;"
echo `date "+%Y-%m-%d %H:%M:%S"` >> /home/mysql/sql_slave_skip_1.log
echo "$Last_SQL_Error_S" >> /home/mysql/sql_slave_skip_1.log
fi
test_slave_status.sh
#!/bin/bash
step=2 #间隔的秒数,不能大于60
for (( i = 0; i < 60; i=(i+step) )); do
/home/mysql/sql_slave_skip_1.sh
sleep $step
done
exit 0
crontab调用:
* * * * * /home/mysql/test_slave_status.sh
以上是关于MySQL复制状态检查脚本的主要内容,如果未能解决你的问题,请参考以下文章