MySQL database bidirectional mirroring, cyclic mirroring (replication)

Source: Internet
Author: User
Tags zen cart

In the MySQL database mirroring post, the data of the primary database A is mirrored to the one-way from database B, and the data read and write of the Zen cart store must be done in database A, and the results will be automatically mirrored into database B. However, the direct operation of database B does not affect database A. For bidirectional database mirroring, the data changes of database A are mirrored to database B, and the changes in database B are replicated to database A at the same time.

For the circular database mirroring, it is multiple databases A, B, C, D, and so on, the modification of any of these databases should be mirrored to other databases at the same time.

Application: The same Zen Cart store database and program, can be placed on different hosts, on any one host new orders, customer information, will be added to the other host database.

To implement bidirectional or circular database mirroring, the first thing to do is to prevent conflicts in the database from automatically incrementing (auto_increment) fields so that multiple databases generate the same increment values.

The following is an example of three host loop mirroring, A is the primary mirror of B, B is the primary image of C, and C is the primary image of a. The following parameters are added to the MySQL setup file/etc/my.cnf on three hosts:

# Host One: United States host A, ip:100.101.102.201
[Mysqld]
Server-id = 10
Log-bin = Mysql-bin
Log-slave-updates
Replicate-same-server-id = 0
Auto_increment_increment = 10
Auto_increment_offset = 1
Master-host = 100.101.102.203
Master-user = Repl_user
Master-password = Repl_password
Report-host = 100.101.102.201

# Host II: China host B, ip:100.101.102.202
[Mysqld]
Server-id = 20
Log-bin = Mysql-bin
Log-slave-updates
Replicate-same-server-id = 0
Auto_increment_increment = 10
Auto_increment_offset = 2
Master-host = 100.101.102.201
Master-user = Repl_user
Master-password = Repl_password
Report-host = 100.101.102.202

# host Three: Local host C, ip:100.101.102.203
[Mysqld]
Server-id = 30
Log-bin = Mysql-bin
Log-slave-updates
Replicate-same-server-id = 0
Auto_increment_increment = 10
Auto_increment_offset = 3
Master-host = 100.101.102.202
Master-user = Repl_user
Master-password = Repl_password
Report-host = 100.101.102.203


Brief description:
Server-id: Database identity, each database identity must be unique;
Replicate-same-server-id: Set to 0 to prevent data loop update;
Auto_increment_increment: This is one of the most important parameters in a circular mirror, indicating an autoincrement of 10, which will allow up to 10 databases to join the loop-mirrored array, and auto-increment fields will not be duplicated.
Auto_increment_offset: This is one of the most important parameters in a circular mirror, representing an offset value that must be unique for each database and between 1 and auto_increment_increment.
Master-host: IP of the primary database server;
Master-user: The mirror user name used to connect to the primary database;
Master-password: The mirror password used to connect to the primary database; 
Report-host: The IP that is provided to the primary database for reverse connection, because the primary database sometimes fails to correctly determine the IP from the server, So it's best to fill in the IP address from the server itself.  


In addition, sometimes only some databases need to be mirrored, which can be added in MY.CNF:  
replicate-do-db = Db_name1  
Replicate-do-db = Db_name2 
Replicate-do-db = Db_name3 

This is just mirroring db_name1/db_name2/db_name3  


If only some databases do not mirror, you can add them in my.cnf:  
Replicate-ignore-db=db_name1 Replicate-ignore-db=db_name2 
Replicate-ignore-db=db_ Name3 

ignores these three databases when mirroring.

MySQL database bidirectional mirroring, cyclic mirroring (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.