MySQL Primary master replication

Source: Internet
Author: User

MySQL Master Master replication setup

Set the Bin-log, and configure the other person for their master

1. Build

1.1 Master1 is configured as a master for Master2

Master configuration (MY.CNF)

[mysqld]server_id=1
log-bin=/usr/local/mysql-5.6.16/log/mysql-bin
Skip-slave-start # Slave replication process does not start on startup
Auto_increment_offset=0
auto_increment_increment=2
replicate-do-db= Test
Replicate-ignore-db=mysql

Start Master1

./bin/mysqld_safe--defaults-file=/usr/local/mysql-5.6.  16/MY.CNF--user=mysql &  


Create a user for replication

*. '   rep1 '@'192.168.80.102'rep1';       


Back up data and restore to Master2 server
--Set read lock, data cannot be updated

Read lock;


--see where to start copying

Mysql>Show master status;+------------------+----------+--------------+------------------+-------------------+|File| Position| binlog_do_db | binlog_ignore_db | Executed_gtid_set | +------------------+----------+--------------+----- -------------+-------------------+| mysql-bin.000001 | 120 | | | | +------------------+- ---------+--------------+------------------+-------------------+ 


--Transfer data

192.168."tar-xzf--c/usr/local/mysql-5.6.16"  


--Release lock

> Unlock tables;


Master2 Configuration (MY.CNF)

[mysqld]server_id=2      # Unique between master and slave
log-bin=/usr/local/mysql-5.6.16/log/mysql-bin
Skip-slave-start # Slave replication process does not start on startup
Auto_increment_offset=1
auto_increment_increment=2
Replicate-do-db=test
Replicate-ignore-db=mysql


Start Master2

./bin/mysqld_safe--defaults-file=/usr/local/mysql-5.6.  16/MY.CNF--user=mysql &  


Configuring Replication Parameters

Mysql> Change MasterToMaster_host=‘192.168.80.101‘,Master_port=320W-> master_user=< Span style= "color: #ff0000;" > ' 


To start Master2 io and SQL threads

> Start slave;


Check

> Show Processlist \g

The following information should appear:
State:waiting for Master to send event
State:slave have read all relay log; Waiting for the slave I/O thread to update it

Or

> Show slave status \g

The following information should appear:
Slave_io_state:waiting for Master to send event
Slave_sql_running_state:slave have read all relay log; Waiting for the slave I/O thread to update it

1.2 Master2 the master configured as Master1
Perform a show master status operation on the Master2 and perform a change master to operation on the Master1 check.

MySQL Primary master replication

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.