Tuesday, April 16, 2013

steps to do replication in mysql (both ways)



################################################################################################
MASTER -MASTER Replication on 2 Server (Primary Server(10.110.19.99)- Standby Server(10.110.19.100))
################################################################################################

################################################################################################
Creating the replication user on both nodes :
################################################################################################


MASTER SERVER ON 10.135.44.3
################################################################################################
grant replication slave, replication client on *.* to repl@"10.135.44.4" identified by "repl";
grant replication slave, replication client on *.* to repl@"Airtel_Ghana_4" identified by "repl";


SLAVE SERVER ON 10.110.19.100 altruist_100
################################################################################################
grant replication slave, replication client on *.* to repl@"10.135.44.3" identified by "repl";
grant replication slave, replication client on *.* to repl@"airtel_Ghana_3" identified by "repl";



################################################################################################
PRIMARY Server My.cnf file
################################################################################################
server-id=1
log-bin=/var/lib/mysql/mysql-bin.log
binlog-do-db=voicechat
replicate-do-db=voicechat
auto_increment_increment = 10
auto_increment_offset = 1

################################################################################################
Standby Server My.cnd File
################################################################################################
server-id=2
log-bin=/var/lib/mysql/mysql-bin.log
binlog-do-db=voicechat
replicate-do-db=voicechat
auto_increment_increment = 10
auto_increment_offset = 2

################################################################################################
Check log position for both server
MASTER SERVER
################################################################################################

mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000009 | 107 | voicechat | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

################################################################################################
SLAVE SERVER
################################################################################################
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000003 | 107 | voicechat | |
+------------------+----------+--------------+------------------+
1 row in set (0.01 sec)

################################################################################################
show master status and then slave status run the following command
################################################################################################
MASTER SERVER
################################################################################################
SLAVE STOP;
CHANGE MASTER TO MASTER_HOST='10.135.44.4', MASTER_USER='repl', MASTER_PASSWORD='repl', MASTER_LOG_FILE='mysql-bin.000003', MASTER_LOG_POS=107;
START SLAVE;
quit;


################################################################################################
SLAVE SERVER
################################################################################################
SLAVE STOP;
CHANGE MASTER TO MASTER_HOST='10.135.44.3', MASTER_USER='repl', MASTER_PASSWORD='repl', MASTER_LOG_FILE='mysql-bin.000009', MASTER_LOG_POS=107;
START SLAVE;
quit;


################################################################################################
Test Replication (Master-Master)
################################################################################################
Create database voicechat;
create table primary1 (name varchar(15));

insert into primary2(name) values('test_primary');
insert into primary2(name) values('test_primary');
insert into primary2(name) values('test_primary');






delete from primary1 ;
insert into abc_primary(name) values('test1_standby');
insert into abc_primary(name) values('test2_standby');
insert into abc_primary(name) values('test3_standby');




show slave status\G;
stop slave;
start slave;

No comments: