First, monitor mysql master-slave synchronization is abnormal, if abnormal, send text messages to the administrator
1) Develop a daemon script to achieve the detection once every 30 seconds.
2) If the error number is: 1158,1159,1008,1007,1062, skip
3) use arrays to achieve the above requirements
#!/bin/sh
errorno=(1158 1159 1008 1007 1062)
mysql_cmd=" mysql -uroot -poldboy124 -S /data/3307/mysql.sock"
while true
do
flag=0
array=($($mysql_cmd -e "show slave status\G"v|egrep '_Running|Behind_Master|SQL_Errno" |awk '{print $NF}'))
if [ "${array[0]}" == "Yes" -a "${array[1]}" == "Yes" -a "${array[2]}" =="0" ]
then
echo "Mysql slave is ok"
else
for((i=0;i<${#errorno[*]};i++))
do
if [ "${array[3]}" -eq "${errorno[$i]}" ];then
$mysql_cmd -e "stop slave &&set global sql_slave_skip_count=1;start slave;"
fi
done
char="Mysql slave is not ok"
echo "$char"
echo "$char"|mail -s "$char" [email protected]
fi
sleep 5
done