You are on page 1of 7

Mysql how master master

replication
Mysql master-master
● First step, we have server 1 and server 2, and in the server 1 with mysql installed
open /etc/mysql/my.cnf and localice the next lines:
#server-id =1
#log_bin = /var/log/mysql/mysql-bin.log
#binlog_do_db = include_database_name
bind-address = 127.0.0.1
and next erase the # and add a # to bind-adress because we need to mysql accept
conections not only by localhost.
It must result:
server-id =1
log_bin = /var/log/mysql/mysql-bin.log
binlog_do_db = treatdb
# bind-address = 127.0.0.1
Mysql master-master
● Then we need to login to mysql console and create an user with
privileges of replication with next commant:
create user 'replicator'@'%' identified by 'password';
grant replication slave on *.* to 'replicator'@'%';
FLUSH PRIVILEGES;
● And we need to see more information about master status with:
show master status;
And of this output we need to write the file and the position.
File : mysql-bin.000001
Position: 416
Mysql master-master
● In the server 2 open the /etc/mysql/my.cnf and do
the same that in the server 1. It must result.
server-id =2
log_bin = /var/log/mysql/mysql-bin.log
binlog_do_db = treatdb
# bind-address = 127.0.0.1
We don't need define bind-address and in server-
id can't be the same.
Mysql master-master
● now, in mysql console create a mysql user with mysql privileges of replication
create user 'replicator'@'%' identified by 'password';
grant replication slave on *.* to 'replicator'@'%';
FLUSH PRIVILEGES;
● next step is said to the instance where must connect.
slave stop;
CHANGE MASTER TO MASTER_HOST = '52.89.254.78', MASTER_USER = 'replicator',
MASTER_PASSWORD = 'repli', MASTER_LOG_FILE = 'mysql-bin.000001',
MASTER_LOG_POS = 416;
slave start
First stop the slave, next put in MASTER_HOST the ip of server 1 in my case 52.89.254.78, in
MASTER_USER put the user created inthe server 1 (replicator), MASTER_PASSWORD need
to put the password of this user. In MASTER_LOG_FILE and MASTER_LOG_POS need to
write the file and the position resulted by the commant show_master_status; respectively.
Mysql master-master
● Then, in server 2, how is also master, execute the commant
show_master_status; in mysql console and see the file and the position resulted
● Now, in server 1 login to mysql console and do the next:
slave stop;
CHANGE MASTER TO MASTER_HOST = '52.26.31.220', MASTER_USER =
'replicator', MASTER_PASSWORD = 'repli', MASTER_LOG_FILE = 'mysql-
bin.000001', MASTER_LOG_POS = 416;
slave start;
How in server 2, stop the slave and put the information about conection with
server 1 this mean that put MASTER_HOST the ip of server 2, in
MASTER_USER and MASTER_PASSWORD write the information about the
user created in server 2, and in MASTER_LOG_FILE and MASTER_LOG_POS
write the file and position resulted of show_master_status, respectively.
How show if it works
● For test, create a table called flower in the server 1 in
database replicate with:
create table treatdb.flowers (`id` varchar(10));
and see the change in the server 2
and next in server 2 create the table new_table
create table treatdb.new_table (`id` varchar(10));
and show the changes in server 1.
● If the databases do the changes mysql master master
works correctly.

You might also like