MySQL Mutual master Automation configuration script

Source: Internet
Author: User

When doing MySQL master-slave and master configuration, if one step at a time, often adjust half a day, a waste. In fact, the principle is very simple, through the IO thread to Bin-log synchronization, and then there is a SQL thread to Bin-log execution again, in order to prevent fighting each other, set an offset, so I want to improve efficiency, the shortest time to build the environment, fortunately, as long as there is a way to do, Write a shell script, the execution finished, the script in the MySQL itself did not do too much optimization, only to ensure that the master and slave, mutual success, sharing, in the study of this thing can be understood.

3 scripts, 1th in the 1th server execution, 2nd in the 2nd server execution, there is a changemaster script, if necessary, very easy to use, not 1 1 of the knock, no nonsense, on the script, inside like IP and password these things or to manually change, Master-host, and so also have to manually change, the study of this one see will understand.


1th Server:

#!/bin/sh#writer:gaolixubinlog_path=/binlog[ -s /var/lib/mysql/mysql.sock ] && mysql!!! installed in the  { echo  system Please uninstall ...; Exit;}   yum -y install mysql-server mysqlservice mysqld startsleep  1mkdir -p  $binlog _pathchown -r mysql:mysql  $binlog _pathmysqladmin -u root  password  ' 123 ' mysql -u root -p123 -e  "Grant replication slave  on *.* to [email protected] '% '  identified by  ' 123 ' "echo " [mysqld ]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysql# disabling symbolic-links is  recommended to prevent assorted security riskssymbolic-links=0log-bin= $binlog _ path/masterlog-bin-index= $binlog _path/masterserver-id=1#expire-logs-days=100#replicate-do-db=test#master-host= 192.168.3.254#master-user=slave#master-password=123binlog-ignore-db=mysqlbinlog-ignore-db=information_schemaauto-increment-increment=2auto-increment-offset=1[mysqld_safe]log-error=/var/log/ Mysqld.logpid-file=/var/run/mysqld/mysqld.pid " > /etc/my.cnfservice mysqld restartecho   "Root user password is 123,slave user password is 123, please change!!! "mysql -u root -p123 -e " Show master status\g "

#!/bin/sh#writer:gaolixubinlog_path=/binlog[ -s /var/lib/mysql/mysql.sock ] && mysql!!! installed in the  { echo  system Please uninstall ...; Exit;} Yum -y install mysql-server mysqlservice mysqld startsleep 1mkdir -p   $binlog _pathchown -r mysql:mysql  $binlog _pathmysqladmin -u root password   ' 123 ' mysql -u root -p123 -e  "grant replication slave on *.*  to [email protected] '% '  identified by  ' 123 ' "echo " [Mysqld]datadir=/var/lib /mysqlsocket=/var/lib/mysql/mysql.sockuser=mysql# disabling symbolic-links is recommended  to prevent assorted security riskssymbolic-links=0log-bin= $binlog _path/ masterlog-bin-index= $binlog _path/masterserver-id=2#expire-logs-days=100#replicate-do-db=test#master-host= 192.168.3.254#master-user=slave#master-password=123binlog-ignore-db=mysqlbinlog-ignore-db=informaTion_schemaauto-increment-increment=2auto-increment-offset=2[mysqld_safe]log-error=/var/log/mysqld.logpid-file =/var/run/mysqld/mysqld.pid " > /etc/my.cnfservice mysqld restartecho " root user password is 123 , slave user password is 123, please change in time!!! "mysql -u root -p123 -e " Show master status\g "


Changemaster script:

#!/bin/sh#writer:gaolixuecho "default to use account slave, password 123" Read-p "Please enter Master_host (IP):" hread-p "Please enter Master_log_file:" Lfread-p "Please enter Master_log_pos:" lph=\ ' $h \ ' lf=\ ' $lf \ ' mysql-u root-p123 <<!change master to master_host= $h, master_user= ' Slave ', master_password= ' 123 ', master_log_file= $lf, master_log_pos= $LP; Start Slave;exit!mysql-u root-p123-e "show slave status\g" |grep slave




This article is from the "Running Linux" blog, so be sure to keep this source http://benpaozhe.blog.51cto.com/10239098/1747615

MySQL Mutual master Automation configuration script

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.