mysql不停服修复主从同步的shell

Standard
#!/bin/sh
#yemaosheng.com上传到从DB修改后执行!
#主DB信息
MDB_IP=192.168.3.30
MDB_USERNAME=op
MDB_PASSWORD=123456
#从DB信息
SDB_IP=127.0.0.1
SDB_USERNAME=root
SDB_PASSWORD=132456
#相互同步的库名
DB=("db_1" "db_2")
 
/etc/init.d/mysqld restart
 
for((i=0;i<${#DB[@]};i++));do
	echo ${DB[${i}]}".sql Dump..."
	mysqldump -h${MDB_IP} -u${MDB_USERNAME} -p${MDB_PASSWORD} -R --triggers  --single-transaction --flush-logs --master-data --database ${DB[${i}]} > ${DB[${i}]}.sql 
	echo "Ok"
done
 
mysql -u${SDB_USERNAME} -p${SDB_PASSWORD} -h${SDB_IP} -e 'slave stop;'
 
for((i=0;i<${#DB[@]};i++));do
	echo ${DB[${i}]}".sql Input..."
	mysql -u${SDB_USERNAME} -p${SDB_PASSWORD} -h${SDB_IP} < ${DB[${i}]}.sql
	echo "Ok"
done
 
mysql -u${SDB_USERNAME} -p${SDB_PASSWORD} -h${SDB_IP} -e 'slave start;'
 
mysql -u${SDB_USERNAME} -p${SDB_PASSWORD} -h${SDB_IP} -e 'show slave status\G'
 
for((i=0;i<${#DB[@]};i++));do
	echo ${DB[${i}]}".sql Del..."
	rm -f ${DB[${i}]}.sql
	echo "Ok"
done

One thought on “mysql不停服修复主从同步的shell

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.