Share a script that automatically jumps to the mysql slave database with error 1062

Source: Internet
Author: User


Share a script that automatically jumps mysql slave Database Error 1062 suddenly loses power from the database, which may cause information in the log not flushed to the hard disk, after the slave database is started, the master and slave databases will get stuck because of 1062 (duplicate primary keys). Here we provide an automatic 1062-hop script www.2cto.com [plain] #! /Bin/sh MYSQL = mysql lastPos = 0 while [1]; do $ MYSQL-uroot-e "show slave status \ G">/tmp /. skip lastError = 'cat/tmp /. skip | grep "Last_ SQL _Errno" | awk '{print $2} ''nowPos = 'cat/tmp /. skip | grep "Exec_Master_Log_Pos" | awk '{print $2} ''if [$ lastError-eq 1062]; then if [$ lastPos-ne $ nowPos]; then echo "blocked, skip one" $ MYSQL-uroot-e "slave stop; set global SQL _slave_skip_counter = 1; slave start; "lastPos = $ nowPos else echo" sleep one second "sleep 1 fi elif [$ lastError-eq 0]; then secondsBehind = 'cat/tmp /. skip | grep "Seconds_Behind_Master" | awk '{print $2} ''if [$ secondsBehind-eq 0]; then echo "done" break else echo "$ secondsBehind seconds behind server" sleep 3 fi else echo "error $ lastError found" break fi done

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.