Mysql自動處理同步報錯

stephenjwq發表於2018-12-12

export LANG=zh_CN

./root/.bash_profile
v_dir=/usr/local/Mysql/bin/
v_user=root
v_passwd=123456
v_log=/home/logs
v_times=10if [-d "${v_log}"];then
 echo "${v_log} has existed before."
else
 mkdir ${v_log}
fi
echo "" > ${v_log}/slave_status.log
echo "" > ${v_log}/slave_status_error.log
count=1
while true
do
 Seconds_behind_master=$(${v_dir}Mysql -u${v_user} -p${v_passwd} -e "show slave status\G;" | awk  -F':' '/Seconds_behind_master/{print $2}')
if [${Seconds_behind_master}!="NULL"];then
 echo "slave is ok!"
 ${v_dir}Mysql -u${v_user} -p${v_passwd} -e "show slave status\G;" >> ${v_log}/slave_status.log
 break
else
 echo "" >> ${v_log}/slave_status_error.log
 date >> ${v_log}/slave_status_error.log
 echo "" >> ${v_log}/slave_status_error.log
 ${v_dir}Mysql -u${v_user} -p${v_passwd} -e "show slave status\G;" >> ${v_log}/slave_status_error.log
 ${v_dir}Mysql -u${v_user} -p${v_passwd} -e "show slave status\G;" |egrep 'Delete_rows' > /dev/null 2>&1
 if [$?=0];then
  ${v_dir}Mysql -u${v_user} -p${v_passwd} -e "stop slave;SET GLOBAL sql_slave_skip_counter=1;start slave;"
 else
  ${v_dir}Mysql -u${v_user} -p${v_passwd} -e "show slave status\G;" |grep 'Last_SQL_Error'
  break
 fi
 let count++
 if [$count -gt ${v_times}];then
  break
 else
 ${v_dir}Mysql -u${v_user} -p${v_passwd} -e "show slave status\G;" >> ${v_log}/slave_status_error.log
 sleep 2
 continue
 fi
fi
done

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9522838/viewspace-2285007/,如需轉載,請註明出處,否則將追究法律責任。

相關文章