-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresync_slave.sh
24 lines (22 loc) · 1.32 KB
/
resync_slave.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash
MASTER_USER=root
MASTER_PASS=rootpasswd
MASTER_HOST=192.168.0.10
SLAVE_USER=root
SLAVE_PASS=slavepasswd
REP_USER=slave
REP_PASS=replicationpasswd
DATABASE=database
/usr/bin/mysql -u$MASTER_USER -h $MASTER_HOST mysql -p$MASTER_PASS -e 'FLUSH TABLES WITH READ LOCK;'
LOGPOS=`/usr/bin/mysql -u$MASTER_USER -h $MASTER_HOST mysql -p$MASTER_PASS -e 'SHOW MASTER STATUS'|grep mysql-bin`
LOG=$(echo $LOGPOS | cut -f1 -d" ")
POS=$(echo $LOGPOS | cut -f2 -d" ")
/usr/bin/mysqldump -B -p$MASTER_PASS -u$MASTER_USER -h$MASTER_HOST --add-drop-database $DATABASE > /tmp/"$DATABASE".sql
/usr/bin/mysql -u$MASTER_USER -h $MASTER_HOST mysql -p$MASTER_PASS -e 'UNLOCK TABLES;'
/usr/bin/mysql -u$SLAVE_USER mysql -p$SLAVE_PASS -e 'STOP SLAVE;'
/usr/bin/mysql -u$SLAVE_USER mysql -p$SLAVE_PASS -e 'RESET SLAVE;'
/usr/bin/mysql -u$SLAVE_USER -p$SLAVE_PASS < /tmp/"$DATABASE".sql
/usr/bin/mysql -u$SLAVE_USER -p$SLAVE_PASS -e "CHANGE MASTER TO master_host='$MASTER_HOST', master_user='$REP_USER', master_password='$REP_PASS', master_log_file='$LOG', master_log_pos=$POS;"
#echo -e "CHANGE MASTER TO master_host='$MASTER_HOST', master_user='$REP_USER', master_password='$REP_PASS', master_log_file='$LOG', master_log_pos=$POS;"
/usr/bin/mysql -u$SLAVE_USER -p$SLAVE_PASS -e 'START SLAVE'
#/usr/bin/mysql -u$SLAVE_USER -p$SLAVE_PASS -e 'SHOW SLAVE STATUS\G'