Mysql自动处理同步报错

来源:这里教程网 时间:2026-03-01 11:49:23 作者:

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

相关推荐