自动执行主从mysql同步的脚本(能执行,但有缺陷)
# vi tongbu.sh
#!/bin/bash
Log=`/usr/local/mysql/bin/mysql -u root -p123456 -e "show slave status \G" | grep Master_Log_File | grep -v 'Relay' | awk -F[:" "]+ '{print $3}'`
Stop=`/usr/local/mysql/bin/mysql -u root -p123456 -e "stop slave"`
Change=`/usr/local/mysql/bin/mysql -u root -p123456 -e "change master to master_host='192.168.1.12',master_user='ming',master_password='123456',master_log_file='$Log'"`
Start=`/usr/local/mysql/bin/mysql -u root -p123456 -e "start slave"`
while [ `whoami` == "root" ];then
do
$Stop | $Change | $Start
done
Log=`/usr/local/mysql/bin/mysql -u root -p123456 -e "show slave status \G" | grep Master_Log_File | grep -v 'Relay' | awk -F[:" "]+ '{print $3}'`
Stop=`/usr/local/mysql/bin/mysql -u root -p123456 -e "stop slave"`
Change=`/usr/local/mysql/bin/mysql -u root -p123456 -e "change master to master_host='192.168.1.12',master_user='ming',master_password='123456',master_log_file='$Log'"`
Start=`/usr/local/mysql/bin/mysql -u root -p123456 -e "start slave"`
while [ `whoami` == "root" ];then
do
$Stop | $Change | $Start
done
:wq
本文转自linux博客51CTO博客,原文链接http://blog.51cto.com/yangzhiming/836581如需转载请自行联系原作者
yangzhimingg