MySQL two-way replication technology classic edition

Source: Internet
Author: User

The following articles mainly describe the MySQL two-way replication technology, including preparing for the server and setting the actual operation steps for the synchronization server. The following is an introduction to the MySQL two-way replication technology, I hope it will help you in this regard.

Setting up MySQL Data Synchronization (one-way and two-way) as a result of the company's business needs, we need to synchronize data between China Netcom and China Telecom, so we made a two-way MySQL synchronization and noted down the process, I will use it later and paste it for your reference.

I. Prepare servers

Because the binlog formats of different MySQL versions (Binary logs) may be different, the best combination is that the MySQL version of the Master is the same or lower than the Slave version, the Master version must not be higher than the Slave version.

More... | less... | In this article, we assume that the Master server and Slave server (Slave) versions are 5.0.27, and the operating system is RedHat Linux 9.

Assume that the Host Name of the synchronization Master is A (IP: 192.168.0.1), the Slave host name is B (IP: 192.168.0.2), and the two basedir directories of MySQL are/usr/local/mysql, datadir is both:/var/lib/mysql.

Ii. Set synchronization server

1. Set synchronization Master

Modify the my. cnf file in

 
 
  1. # Replication Master Server (default)   
  2. # binary logging is required for replication  

Add the following content:

 
 
  1. log-bin=/var/log/mysql/updatelog   
  2. server-id = 1   
  3. binlog-do-db=test   
  4. binlog-ignore-db=mysql  

Restart MySQL and create a MySQL account for synchronization

 
 
  1. GRANT REPLICATION SLAVE,RELOAD,SUPER, ON *.* TO back@192.168.0.2 IDENTIFIED BY 'back' ;   
  2. FLUSH PRIVILEGES ;  

2. Set synchronization Slave

Modify the my. cnf file and add

 
 
  1. Server-id = 2
  2. Master-host = 192.168.0.1
  3. Master-user = back
  4. Master-password = back
  5. Master-port = 3306
  6. Replicate-ignore-db = mysql (my version is Ver 14.14 Distrib 5.1.22-rc. This parameter does not seem to be available)
  7. Replicate-do-db = test

Restart MySQL

3. Start Synchronization

Run the MySQL command on the master server.

 
 
  1. show master status;  

Display (of course, this is my machine. You cannot be the same as me, just an example)

 
 
  1. +------------------+----------+-------------------+------------------+   
  2. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |   
  3. +------------------+----------+-------------------+------------------+   
  4. | updatelog.000028 | 313361 | test | mysql |   
  5. +------------------+----------+-------------------+------------------+  

Under the slave server A MySQL command:

 
 
  1. slave stop;   
  2. CHANGE MASTER TO MASTER_LOG_FILE='updatelog.000028',MASTER_LOG_POS=313361;slave start;  

Use show slave statusG; to check synchronization from the server

 
 
  1. Slave_IO_Running: Yes   
  2. Slave_SQL_Running: Yes  

If all are yes, it indicates that the synchronization is in progress.

Write Data to the table and test whether the synchronization is successful. If the synchronization fails, it is definitely not your RP problem. Then check the operation steps!

4. Set MySQL two-way Synchronization

Modify my. cnf of server B and add

 
 
  1. log-bin=/var/log/mysql/updatelog   
  2. binlog-do-db=test   
  3. binlog-ignore-db=mysql  

Restart MySQL and create a MySQL account for synchronization

 
 
  1. GRANT REPLICATION SLAVE,RELOAD,SUPER, ON *.* TO back@192.168.0.1 IDENTIFIED BY 'back' ;   
  2. FLUSH PRIVILEGES ;  

Modify my. cnf of server A and add
 

 
 
  1. master-host = 192.168.0.2   
  2. master-user = back   
  3. master-password = back   
  4. master-port = 3306   
  5. replicate-ignore-db=mysql   
  6. replicate-do-db=test 

Restart MySQL

Under the MySQL command of master server B

 
 
  1. show master status;   
  2. +------------------+----------+-------------------+------------------+   
  3. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |   
  4. +------------------+----------+-------------------+------------------+   
  5. | updatelog.000028 | 13753 | test | mysql |   
  6. +------------------+----------+-------------------+------------------+  

Run the MySQL Command on server:

 
 
  1. slave stop;   
  2. CHANGE MASTER TO MASTER_LOG_FILE='updatelog.000028',MASTER_LOG_POS=13753;   
  3. slave start;  

In fact, this is the reverse operation of A-> B one-way synchronization! MySQL bidirectional synchronization is that simple!

Related Article

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.