In another article, we learned how to set up a Master-Slave type of replication, today i’m going to show you how to set up a Master-Master one, meaning both nodes are open in Read/Write mode. Show Both nodes will be in sync and will accept any modifications (and will replicate it to the other one) 🛠 PrerequisitesFirst of all, let’s make a list of what we need:
🖥 Scenario:First Node
Second Node
⚙️ SetupOnce you have your VMs all set up, with MySQL installed and configured, it’s time to set up the replicas. We will start by replicating the First Node to the Second one, then we will configure the First one to replicate any modifications from the Second. Setting up a Master-Master replica it’s pretty much the same as setting up a Master-Slave one, with one additional step at the end. Firewalld RuleUnless you want to disable the firewall, you need to add a rule to let clients connect to your Database.
Node PriorityOn both Nodes, edit the MySQL configuration file
By adding these two lines First Nodebind-address = 192.168.1.35
server-id = 1
log_bin = mysql-bin Second Nodebind-address = 192.168.1.36
server-id = 2
log_bin = mysql-bin And then restart the mysql on both nodes
Create ‘Replica’ UserOn the first node, create the user that will replicate the data
Now check the Master Status
And note down the binlog file name and the position *************************** 1. row *************************** File: mysql-bin.000001 Position: 324 Binlog_Do_DB: Binlog_Ignore_DB: Executed_Gtid_Set: 1 row in set (0.00 sec) Replicate to the Second NodeNow on the Second Node, connect to your MySQL database and stop any running slave process
Ignore the warning Change now the master to the primary node, be careful to use the correct
Ignore the warning Once done, start the slave process to begin the replication
Give it some time to connect to the First Node and execute the command
Here you only have to care about 4 main things: Slave_IO_State: Waiting for master to send event Master_Host: 192.168.1.35 Slave_IO_Running: Yes Slave_SQL_Running: Yes Now that we have a fully functional Master-Slave replication, we need to convert it into a Master-Master one, by configuring the First node to accept data from the Second one. First of all, we need to create the replica user
Then, we need to know the binlog name and position of the “slave”, so let’s execute this command on the Second node:
*************************** 1. row *************************** File: mysql-bin.000002 Position: 1442 Binlog_Do_DB: Binlog_Ignore_DB: Executed_Gtid_Set: 1 row in set (0.00 sec) Replicate to the First NodeNow that we have all the info, let’s proceed with the configuration. On the First Node, connect to the MySQL and first of all, stop any running slave process
Ignore the warning Now execute the
Ignore the warning Once done, time to start the slave process again
Last thing we need to do, is check the slave status, to ensure everything’s working fine
Slave_IO_State: Waiting for master to send event Master_Host: 192.168.1.36 Slave_IO_Running: Yes Slave_SQL_Running: Yes How does master master replication work in MySQL?The MySQL replication feature allows a server - the master - to send all changes to another server - the slave - and the slave tries to apply all changes to keep up-to-date with the master.
How do I set master to master replication?Configure Database Replication. While logged into MySQL on Server 1, query the master status: SHOW MASTER STATUS; ... . On Server 2 at the MySQL prompt, set up the replica functionality for that database. ... . On Server 2, query the master status. ... . Set the replica database status on Server 1, utilizing similar commands as in step 2.. What is replication in MySQL?Replication enables data from one MySQL database server (known as a source) to be copied to one or more MySQL database servers (known as replicas). Replication is asynchronous by default; replicas do not need to be connected permanently to receive updates from a source.
How does multi master replication work?Multi-master replications mean there is more than one node that acts as master nodes. Data is replicated between nodes and updates and insertion can be possible on a group of master nodes. In that case, there are multiple copies of the data.
|