Complete MySQL master-slave deployment with one click.

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.