标签 Delete_rows错误 下的文章

  1. #!/bin/bash
  2. ########################################################################
  3. ##
  4. ##此脚本是用来自动处理同步报错的,默认跳过10次。
  5. ##
  6. ##只有Last_SQL_Error:Could not execute Delete_rows event on table ...;Can't find record ## in ...;Error_code:1032;handler error HA_ERR_KEY_NOT_FOUND;the event's master log ## bin-log.000001.end_log_pos ...
  7. ##这种情况才跳过,其他的情况自行处理,以免丢失数据。
  8. ##
  9. #########################################################################
  10. export LANG=zh_CN
  11. . /root/.bash_profile
  12. v_dir=/usr/local/mysql/bin/
  13. v_user=root
  14. v_password=
  15. v_log=/home/logs/
  16. v_time=10
  17. if [ -d "${v_log}" ];then
  18. echo "${v_log} has existed before."
  19. else
  20. mkdir ${v_log}
  21. fi
  22. echo "" > ${v_log}/slave_status.log
  23. echo "" > ${v_log}/slave_status_error.log
  24. count=1
  25. while true
  26. do
  27. Seconds_Behind_Master=$(${v_dir}mysql -u${v_user} -p${v_password} -e "show slave status\G;" | awk -F':' '/Seconds_Behind_Master/{print $2}')
  28. if [ "$Seconds_Behind_Master" != "NULL" ];then
  29. echo "slave is ok!"
  30. ${v_dir}mysql -u${v_user} -p${v_password} -e "show slave status\G;" >> ${v_log}/slave_status.log
  31. break
  32. else
  33. echo "" >> ${v_log}/slave_status_error.log
  34. date >> ${v_log}/slave_status_error.log
  35. echo "" >> ${v_log}/slave_status_error.log
  36. ${v_dir}mysql -u${v_user} -p${v_password} -e "show slave status\G;" >> ${v_log}/slave_status_error.log
  37. ${v_dir}mysql -u${v_user} -p${v_password} -e "show slave status\G;" | egrep 'Delete_rows' > /dev/null 2>&1
  38. if [ $? = 0 ];then
  39. ${v_dir}/mysql -u${v_user} -p${v_password} -e "stop slave;set global sql_slave_skip_counter=1;start slave;"
  40. else
  41. ${v_dir}mysql -u${v_user} -p${v_password} -e "show slave status\G;" | grep 'Last_SQL_Error'
  42. break
  43. fi
  44. let count++
  45. if [ $count -gt "${v_times}" ];then
  46. break
  47. else
  48. ${v_dir}mysql -u${v_user} -p${v_password} -e "show slave status\G;" >> ${v_log}/slave_status_error.log
  49. sleep 2
  50. continue
  51. fi
  52. fi
  53. done