MySQL5.5 master-master replication configuration method and test results

Source: Internet
Author: User

1. Environment: CentOS5.5 x84, MySQL5.5.15
2. Two machines: master1: 192.168.5.143master2: 192.168.0.149
3. Compile and install MySQL separately and test the connection.
4. Create a user on both machines and grant the copy permission: master1:

  1. Mysql> CREATE USER 'Test12'@'%';
  2. Mysql> GRANTREPLICATION SLAVEON *.* TO 'Test12'@'%' IDENTIFIED BY 'Test12';
Master2:
  1. Mysql> CREATE USER 'Test34'@'192. 168.5.143';
  2. Mysql> GRANTREPLICATION SLAVEON *.* TO 'Test34'@'192. 168.5.143' IDENTIFIED BY 'Test34';
The host can be set as long as it is connected to the other party. For permissions, you only need to have the replication slave permission.
5. Add my. cnf on master1:
  1. [Mysqld]
  2. # For repl
  3. Server-id = 1
  4. Log-bin = mysql-bin
  5. Auto-increment = 2 # Set to the total number of servers in the entire structure
  6. Auto-increment-offset = 1 # Set the starting point for automatic database growth to avoid primary key conflicts during data synchronization between the two servers
6. Add my. cnf on master2:
  1. [Mysqld]
  2. # For repl
  3. Server-id = 2
  4. Log-bin = mysql-bin
  5. Auto-increment = 2
  6. Auto-increment-offset = 1
7. Restart the services on the two machines.
8. Master master2 is specified on master1:
  1. Mysql> CHANGEMASTERTO
  2. ->MASTER_HOST='192. 168.0.149',
  3. ->MASTER_USER='Test34',
  4. ->MASTER_PASSWORD='Test34';
  5. Query OK,0RowsAffected(0.19 sec)

  6. Mysql> STARTSLAVE;
  7. Query OK,0RowsAffected(0.00 sec)
9. Master master1 is specified on master2:
  1. Mysql> CHANGEMASTERTO
  2. ->MASTER_HOST='192. 168.5.143',
  3. ->MASTER_USER='Test12',
  4. ->MASTER_PASSWORD='Test12';
  5. Query OK,0RowsAffected(0.18 sec)

  6. Mysql> STARTSLAVE;
  7. Query OK,0RowsAffected(0.00 sec)
10. test lab 1: Start two services and perform operations on any mysql instance. Experiment 2: Start two services and add 20 warehouses using the tpcc tool on master1. The data occupies about 1.9 GB of hard disk and count (*) on the two machines. The data is consistent. Experiment 3: Start master1 and use the tpcc tool to add a warehouse and start master2. After synchronization for a period of time, calculate count (*) and the results are consistent.
Ps, MySQL master-master replication is actually two-way master-slave replication.

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.