#!/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