MySQL's dual master mode

Source: Internet
Author: User

MySQL Primary master replication configuration

Server1 ip:192.168.0.231
Server2 ip:192.168.0.234


Change the MySQL configuration file for both hosts
Vim/etc/my.cnf
Server1 add
Server-id=1
Log-bin=mysqlmaster-bin.log
auto-increment-increment=2
Auto-increment-offset=1


Server2 add
server-id=2
Log-bin=mysqlmaster-bin.log
auto-increment-increment=2
auto-increment-offset=2

Description: The value of Auto-increment-increment is set to the total number of servers in the entire structure, this experiment is two servers, so the value is 2
Auto-increment-offset is used to set the starting point of automatic growth in the database, because the server has set an autogrow value of 2, so their starting point must be different, in order to avoid a primary key conflict between two server data synchronization

You can also set Replicate-do-db=database-name to specify the databases that need to be synchronized

Restarting the MySQL service makes the configuration effective

Log in to MySQL

Add users required to synchronize data

Server1 on

Mysql>grant REPLICATION SLAVE on * * to ' systop1 ' @ ' 192.168.0.% ' identified by ' systop ';

Server2 on

GRANT REPLICATION SLAVE on * * to ' systop2 ' @ ' 192.168.0.% ' identified by ' systop ';


View the master status of two servers

Server1

SHOW MASTER STATUS;
+------------------------+----------+--------------+------------------+-------------------+
| File | Position | binlog_do_db | binlog_ignore_db | Executed_gtid_set |
+------------------------+----------+--------------+------------------+-------------------+
|      mysqlmaster-bin.000002 |              120 |                  |                   | |



Server2

Show master status;
+------------------------+----------+--------------+------------------+-------------------+
| File | Position | binlog_do_db | binlog_ignore_db | Executed_gtid_set |
+------------------------+----------+--------------+------------------+-------------------+
|      mysqlmaster-bin.000001 |              336 |                  |                   | |


Description Binary Log path

Execute on Server2

Change MASTER to master_host= ' 192.168.0.231 ', master_user= ' systop1 ', master_password= ' systop ', master_log_file= ' Mysql-bin.000002 ', master_log_pos=120;


Execute on Server1

Change MASTER to master_host= ' 192.168.0.234 ', master_user= ' systop2 ', master_password= ' systop ', master_log_file= ' Mysqlmaster-bin.000001 ', master_log_pos=336;



Turn on the copy function

Both machines are executed.
Start slave;

View Replication Connection Status
Perform
show slave status \g;
View Slave_io_running:yes
Slave_sql_running:yes
All show yes to start normal

Test: Both servers do data update operations to see if the data is updated

MySQL's dual master mode

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.