本帖最后由 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
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
编辑回复