Maintenance scripts for MySQL master-slave replication

Source: Internet
Author: User

#!/bin/bash


#date is 2016-7-13


##### Master

Mstool= "/usr/local/mysql/bin/mysql-h mysql_m.bj.com-uroot-proot-p 3306"

##### from

Sltool= "/usr/local/mysql/bin/mysql -H 192.168.153.92-uroot-proot-p 3306"


Declare-a Slave_stat


Slave_stat= ($ ($sltool-E "show slave status\g" |grep Running |awk-f: ' {print $} '

))


If ["${slave_stat[0]}" = "yes"-a "${slave_stat[1]}" = "yes"]

Then

echo "OK slave is running"

Exit 0

Else

echo "Critical Slave is Error"

Echo

echo "*********************************************************"

echo "Now starting replication with Master mysql!"




File= ' $mstool-e "show Master Status\g" |grep-i "File" |awk ' {print $} '

Pos= ' $mstool-e "show Master Status\g" |grep-i "Pos" |awk ' {print $} '

$sltool-E "slave stop;change Master to master_host= ' mysql_m.bj.com ', master_port=3306,master_user= ' Mysync ', master_ Password=mysync ', master_log_file= ' $file ', master_log_pos= $pos; slave start;

Sleep 3

$sltool-E "show slave status\g;" | grep Running

Echo

echo "Now Replication is finished!"

Echo

echo "**********************************************************"

Exit 2

Fi



You can change the relevant parameters according to your own environment.



Maintenance scripts for MySQL master-slave replication

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.