First, Introduction
In the master-slave copy of the previous article: http://www.cnblogs.com/lay2017/p/9043985.html
We learned that MySQL writes logs through master, slave reads and executes the log content to achieve slave data consistent with master. So based on this principle, we can realize the replication function of two master.
Broadly as follows:
1, both master open Log-bin write log
2, ID to repeat
3. Configure the tables to be copied
4, two master respectively to give replication slave slave copy permission;
5. Turn on replication separately
Second, two master to turn on the host log separately
Enter two master machines, repair my.cnf files (vim/etc/my.cnf), and add the following:
# Dual Master Configuration
# log file name Log-bin=master-bin
# The unique identifier is usually the machine's IP tail number server-id=144# ID to repeat the configuration auto_increment_increment= several machines with a few auto_increment_offset= in order, for example (first: 1 ; second: 2) # Set the database name for the dual master replication replicate-do-db= Database
Third, to each other to give replication permissions
Execute separately on both machines
Mysql>grant replication Slave on * * to ' login username ' @ ' The other's IP address ' identified by ' give each other login password ';
Note: this is *. *, can only configure all databases because replication slave permissions can only be used for the global database, that is why we second step in the configuration file to configure the name of the database allowed to replicate
Four, respectively, the host point to each other
1) through: Mysql>show Master status; View the log file name and address of the other party
+-------------------+----------+--------------+------------------+-------------------+
| File | Position | binlog_do_db | binlog_ignore_db | Executed_gtid_set |
+-------------------+----------+--------------+------------------+-------------------+
| master-bin.000003 | 407 | | | |
+-------------------+----------+--------------+------------------+-------------------+
2) Configure the host to point to by the following command:
Change MASTER tomaster_host= ' each other's IP ', master_user= ' user name ', master_password= ' password ', master_log_file= ' log file name ', Master_log_ pos= log address;
V. Turn on replication
Start slave;
Note: It is best to clear the database when doing the test, if you have configured the master-slave replication, it is also better to first reset the following master and slave, reset command as follows:
Mysql>reset Master;mysql>reset Slave;
V. Viewing status
Executed on two machines, respectively.
Mysql>show slave status\g;
If there is no problem, you will see something like the following:
...... Slave_IO_Running:YesSlave_SQL_Running:Yes ...
Note: Two threads require a status of yes to indicate that replication is open successfully
The above dual master replication configuration
Reference article:
Https://www.cnblogs.com/phpstudy2015-6/p/6485819.html
Https://www.cnblogs.com/tianshupei88/p/5075367.html
MySQL primary master replication for Linux systems (dual master replication)