MySQL bidirectional Synchronization

Source: Internet
Author: User

1. Server Status
Server A: 192.168.1.1
Server B: 192.168.1.2

2. Create a synchronization user
Host Domain A: 192.168.1.2 User Name A: sync_a Password A: aaa
Host Domain B: 192.168.1.1 username B: sync_ B password B: bbb
At leastAssign the following permissions to grant replication slave

3. Execute flush privileges

4. Stop MySQL

5. Configure my. cnf (my. ini)

Server Server B
User = mysql
Log-bin = mysql-bin
Server-id = 1
Binlog-do-db = test
Binlog-ignore-db = mysql
Replicate-do-db = test
Replicate-ignore-db = mysql
Log-slave-updates
Slave-skip-errors = all
Sync_binlog = 1
User = mysql
Log-bin = mysql-bin
Server-id = 2
Binlog-do-db = test
Binlog-ignore-db = mysql
Replicate-do-db = test
Replicate-ignore-db = mysql
Log-slave-updates
Slave-skip-errors = all
Sync_binlog = 1

Server-id requiredUnique
Binlog-do-db and replicate-do-dbYesSynchronized Database
Binlog-ignore-db and replicate-ignore-dbNoSynchronized Database
PleaseNoAdd the following command andNot solvedThe uid hop number is incorrect. On the contrary, the following two lines of commands cause the uid hop number.Culprit
Auto_increment_increment = 2
Auto_increment_offset = 1

6. Restart MySQL

7. log on to the MySQL console.

Server:
Show master status \ G
Flush tables with read lock;
Server B:
Show master status \ G
Flush tables with read lock;

Record the File and Position of the two servers at the same time. Assume that:

A: File: mysql-bin.000001
Position: 001
B: File: mysql-bin.000002
Position: 002

Server:
Change master
-> Master_host = '192. 168.1.2 ',
-> Master_user = 'sync _ B ',
-> Master_password = 'bbb ',
-> Master_log_file = 'mysql-bin.000002 ',
-> Master_log_pos = 002;
Server B:
Change master
-> Master_host = '2017. 168.1.1 ',
-> Master_user = 'sync _ ',
-> Master_password = 'aaa ',
-> Master_log_file = 'mysql-bin.000001 ',
-> Master_log_pos = 001;

The data entered here is complete.Opposite

8. Run show processlist \ G to check whether the synchronization is successful.

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.