Wednesday, September 25, 2019

Mysql- Master - Slave Replication setup.


Below steps should be done in same outage. Take Master server down and take backup and restore to the slave side to make sure they both are look-alike as per Data.


1) Add below parameters in /etc/my.cnf for Master-side Mysql Instance and for Slave-side Mysql Instance repectively.

Master-side Configuration:
# To enable MySQL replication, you need to enable binary logging.

sync_binlog=1  # enable "1" if replication is used for master else comment this to disable
binlog_checksum = NONE
binlog_format = STATEMENT
log-bin=/mysql/log/hostname-bin.log
log-bin-index=/mysql/log/hostname-bin.index

Slave-side Configuration:

skip-slave-start   # it will not start replication automatically when mysql is started.
relay-log=/mysql/log/slave-relay-bin
relay-log-index=/mysql/log/slave-relay-bin.index


2) stop mysql on Master side and Slave side.
systemctl stop mysqld

3) start mysql on Master side and Slave side.
4) On Master-Side:
   create user 'repl_user'@'Slave-IP' identified by 'Password#';
   grant replication slave on *.* to 'repl_user'@'Slave-IP' identified by 'Password#';
   flush privileges;
   FLUSH TABLES WITH READ LOCK;
   show variables like 'sql_log_bin';
   set sql_log_bin=0;  --- to disable binary logging    we are doing this to disable replication for sometime till we setup slave with master backup and config etc.
   -- when ready to run command on step 5 on Slave-side
   unlock tables;
   reset master;
   show master status\G; --- note down the details for below command on slave side.
 
     
5) On Slave_side:
CHANGE MASTER TO MASTER_HOST='MAster-IP',MASTER_USER='repl_user',MASTER_PASSWORD='Password#',MASTER_LOG_FILE='hostname-bin.000001',MASTER_LOG_POS=50;
start slave;
show slave status\G;
show processlist\G; ---- check and see if you see replication process is running on both sides.

6) create a dummy table(and insert rows) on Master-Side and see if it got created on Slave-side.



No comments:

Post a Comment

PostgreSql: Useful Commands-

 1)   ************************* Users ***************************  -- List of users with roles assigned: SELECT usename AS role_name,   CASE...