MySQL Skip master-slave error tool (mysqlha_skiperror.sh)

Source: Internet
Author: User

Tool Name: mysqlha_skiperror.sh

Tool usage: For MySQL skip master and slave errors

Tool Parameters: Options:

-P Port Specifies ports
-N number specifies that skipping errors does not specify a default of 10 times (log is logged if you do not know can be set larger)

-C error code take, as the separator specifies that skipping error status codes can be skipped by multiple, delimited

Tool Example: Mysqlha_skiperror.sh-p 4444-c 1032

Tool execution Results:

could not execute Write_rows event on table test.t; Duplicate entry ' for key ' PRIMARY ', error_code:1062; Handler error Ha_err_found_dupp_key; The event ' s master Log mysql-bin.000011, End_log_pos 6621
Could not execute Write_rows event on table test.t; Duplicate entry ' for key ' PRIMARY ', error_code:1062; Handler error Ha_err_found_dupp_key; The event ' s master Log mysql-bin.000011, End_log_pos 6800
Could not execute Delete_rows event on table testone.t1; Can ' t find record in ' T1 ', error_code:1032; Handler error ha_err_key_not_found; The event ' s master Log mysql-bin.000011, End_log_pos 6983
2016-08-08 17:44:25 slave is ok
count_total=3

Tool log: Will be generated under the current dir skiperror.txt inside is a detailed error content, read can be deleted.

Example:

650) this.width=650; "class=" Confluence-embedded-image "src=" http://wiki.op.xywy.com/download/attachments/ 14254982/image2016-8-8%2017%3a45%3a23.png?version=1&modificationdate=1470649524000&api=v2 "alt=" Image2016-8-8%2017%3a45%3a23.png?version "/>

#!/bin/bash

#date 2016-08-04

#author [email protected]



Currenttime= ' Date ' +%y-%m-%d%h:%m:%s "'

function Helpfunc () {

Echo

echo "Please check your input!!!!"

echo "Options:"

echo "-P port"

echo "-N number"

echo "-C error code take, as the separator"


echo "Please enter the port number and the default skip number, not the number of times the default is 10"


}


count_num=10

code=1062,1032

If [$#-lt 1];

Then

Helpfunc

Exit 1

Else


While getopts "P:N:C:" Option

Do

Case $Option in

P) port= $OPTARG;;

N) count_num= $OPTARG;;

C) code= $OPTARG;;

*) Helpfunc; Exit 1;;;

Esac

Done


Count_total=0

Logdir=/data/logs/skiperror

If [-D $logdir];then

echo "$logdir exists"

Else

Mkdir-p $logdir

Fi


#for ((a=0;a++;a<10));

For I in $ (seq $count _num)

Do

Sql_yn= '/etc/dbbin/mysqlha_login.sh-p $port-e "show slave Status\g" | grep slave_sql_running | awk ' {print $} '

If ["$sql _yn" = "Yes"];then

echo "$currentTime slave is OK" >> $logdir/skiperror.txt

echo "$currentTime slave is OK"

echo "count_total= $count _total" >> $logdir/skiperror.txt

echo "Count_total= $count _total"

Exit 3;

Else

For Error_code in $code

Do

Err= '/etc/dbbin/mysqlha_login.sh-p $port-e "show slave Status\g" | grep Last_errno: | awk ' {print $} '

If ["$err"-eq "$error _code"] && ["$sql _yn" = "No"] Then

"$currentTime" >> $logdir/skiperror.txt

/etc/dbbin/mysqlha_login.sh-p $port-E "show slave Status\g" | grep Last_sql_error | Awk-f ' _error: ' {print $} ' >> $logdir/skiperror.txt

/etc/dbbin/mysqlha_login.sh-p $port-E "show slave Status\g" | grep Last_sql_error | Awk-f ' _error: ' {print $} '

/etc/dbbin/mysqlha_login.sh-p $port-E "set global Sql_slave_skip_counter=1;start Slave"

#count_total = ' expr $count _total + 1 '

((count_total= $count _total + 1))

Else

Continue

Fi

Done

Fi

Done


This article is from the "10937712" blog, please be sure to keep this source http://10947712.blog.51cto.com/10937712/1845606

MySQL Skip master-slave error tool (mysqlha_skiperror.sh)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.