Environmental statement:
Master-Slave server in 192.168.0.0/24 network segment
master-->ip:192.168.0.88
master-->ip:192.168.0.89
Script master-ip:192.168.0.88 in master---primary database
#!/bin/sh# function: this is used for mysql-master role# made by zhigang.wang# contact: [email protected]myuser=rootmypass= "Rootpwd" PORT=3306SOCKET=/data/ $PORT/mysql.sockdata_path=/data/backuplog_file=${data_path}/mysqllogs_ ' date +%f '. LogDATA_FILE=${DATA_PATH }/mysql_backup_ ' date +%f '. sql.gzmysql_dir=/application/mysql/binmysql_cmd= "$MYSQL _dir/mysql -u$ myuser -p$mypass -s $SOCKET "mysql_dump=" $MYSQL _dir/mysqldump -u$myuser -p$mypass -S $SOCKET -A -B -F --single-transaction --events "[ ! -d $DATA _path ] && mkdir -p $DATA _path[ ' $MYSQL _cmd -e "Select user,host from mysql.user" |grep rep|wc -l ' -ne 1 ] && $MYSQL _cmd -e "grant replication slave on *.* to ' rep ' @ ' 192.168.0.% '  IDENTIFIED&NBsp;by ' rep123 '; " $MYSQL _cmd -e "flush tables with read lock;" echo "-----show master status result-----" > $LOG _file$mysql_cmd -e "show master status;" >> $LOG _file${mysql_dump} | gzip > $DATA _file$mysql_cmd -e "unlock tables; " cat $LOG _file
In slave---script from the database
#!/bin/sh# function: this is used for mysql-master role# made by zhigang.wang# contact: [email protected]myuser=rootmypass= "Rootpwd" PORT=3306SOCKET=/data/ $PORT/mysql.sockdata_path=/data/backuplog_file=${data_path}/mysqllogs_ ' date +%f '. LogDATA_FILE=${DATA_PATH }/mysql_backup_ ' date +%f '. sql.gzmysql_dir=/application/mysql/binmysql_cmd= "$MYSQL _dir/mysql -u$ myuser -p$mypass -s $SOCKET "#recovercd ${DATA_PATH} && rm -f Mysql_backup_ ' date +%f '. Sqlgzip -d mysql_backup_ ' date +%f ' .sql.gz$mysql_cmd < mysql_backup_ ' date +%f '. sql#config slavecat | $MYSQL _cmd<< eofchange Master to master_host= ' 192.168.0.88 ', master_port=3306,master_user= ' rep ', master_ Password= ' rep123 ', master_log_file= "' tail -1 $LOG _file|cut -f1 '", master_log_pos= ' tail -1 $LOG _file|cut -f2 '; eof$mysql_cmd -e "start slave;" $MYSQL _cmd -e "Show slave status\g" |egrep "io_running| Sql_running " >> $LOG _filemail -s " Mysql-slave build status " [email protected] < $LOG _file
This article is from the "technical achievements of the Future" blog, please make sure to keep this source http://jishuweiwang.blog.51cto.com/6977090/1431327