mysql检查主从同步脚本

回复 收藏
本帖最后由 yanggang 于 2015-12-19 23:59 编辑

mysql主从同步脚本,如果异常,就发送给邮件。
如果同步出现如下错误号(1158 1159 1008 1007 1062)。请跳过错误

#!/bin/bash
mysql_cmd="mysql -uroot -p123456 -S /tmp/mysql.sock"
errorno=(1158 1159 1008 1007 1062)                #数值定义错误号

while true;do
array=(`$mysql_cmd -e ("show slave status\G" | egrep '_Running:|Seconds_Behind|Last_SQL_Errno' | awk '{print $NF}')`)

        if [ ${array[0]} = "Yes" ] && [ ${array[1]} = "Yes" ] && [ ${array[2]} = "0" ];then

                echo "mysql slave is ok"
        else
                for ((i=0;i<${#errorno[$i]};i++));do                                                
                        if [ ${array[3]} = "${errorno[$i]}" ];then
                        $mysql_cmd -e "stop slave;set global sql_slave_skip_counter=1;start slave;"
                        fi      
                done
                char= "mysql slave is not ok"   
                echo "$char"
                echo "$char" | mail -s "$char" xxxx@qq.com
        fi
sleep 30
done



2015-12-19 23:54 举报
已邀请:
0

泡沫。

赞同来自:

脚本不能运行啊 报语法错误
0

rolay8

赞同来自:

注意论坛字符问题
0

fansik

赞同来自:

把错误贴出来看看,很有可能是路径的问题
0

迷城

赞同来自:

{:4_91:}

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: