MySQL Master Master Replication
MySQL Master Master Repliction Tutorial
This tutorial describes how to set up MySQL master-master replication. We need to replicate MySQL servers to achieve high-availability (HA). In my case I need two masters that are synchronized with each other so that if one of them drops down, other could take over and no data is lost. Similarly when the first one goes up again, it will still be used as slave for the live one.
Here is a basic step by step tutorial, that will cover the mysql master and slave replication and also will describe the mysql master and master replication.
Notions: we will call system 1 as master1 and slave2 and system2 as master2 and slave 1.
Install mysql on master 1 and slave 1. configure network services on both system, like
Master 1/Slave 2 ip: 192.168.16.4
Master 2/Slave 1 ip : 192.168.16.5
On Master 1, make changes in my.cnf:
On master 1, create a replication slave account in mysql.
mysql> grant replication slave on *.* to 'firstname.lastname@example.org \
and restart the mysql master1.
Now edit my.cnf on Slave1 or Master2 :
Restart mysql slave 1 and at
mysql> start slave;
Slave_IO_State: Waiting for master to send event
Relay_Log_File: MASTERMYSQL02-relay-bin.000015 Relay_Log_Pos: 3630
1 row in set (0.00 sec)
Above highlighted rows must be indicate related log files and Slave_IO_Running and Slave_SQL_Running: must be to YES.
On master 1:
mysql> show master status;
On Master2/Slave 1, edit my.cnf and master entries into it:
Create a replication slave account on master2 for master1:
mysql> grant replication slave on *.* to 'email@example.com identified by 'slave2';
Edit my.cnf on master1 for information of its master.
Restart both mysql master1 and master2.
On mysql master1:
mysql> start slave;
On mysql master2:
mysql > show master status;
On mysql master 1:
mysql> show slave status\G;
Check for the hightlighted rows, make sure its running. Now you can create tables in the database and you will see changes in slave. Enjoy!!