Learn Devops tools online from the blog. Devops Institute Ahmedabad.

MySQL replication allows you to have an exact copy of a database from a master server on another server (slave), and all updates to the database on the master server are immediately replicated to the database on the slave server so that both databases are in sync. This is not a backup policy because an accidentally issued DELETE command will also be carried out on the slave; but replication can help protect against hardware failures though. 







Create Replication User 
Create an account on the master server that the slave server can use to connect. This account must be given the 


REPLICATION SLAVE privilege: 
#mysql -uroot -p
#CREATE USER 'user_vishal'@'localhost' IDENTIFIED BY 'pass_123';
#GRANT REPLICATION SLAVE ON *.* TO 'user_vishal'@'Slave Ip Addd' IDENTIFIED BY 'pass_123';
#mysql>FLUSH PRIVILEGES;
#show master status\G;

In master server:-
vim /etc/my.cnf
log-bin=mysql-bin
server-id=1
innodb_flush_log_at_trx_commit=1
sync_binlog=1

Restart MySQl


On Slave Server:-
vim /etc/my.cnf
server-id=2
master_host=(master ip)
master_user=vyas
master_password=123

Restart MySQl
#mysql -uroot -p
CHANGE MASTER TO MASTER_HOST='Master Host',
MASTER_HOST=’X.X.X.X’,
MASTER_USER=’user’,
MASTER_PASSWORD=’password’,
MASTER_PORT=3306,
MASTER_LOG_FILE=’mysql-bin.000001?,
MASTER_LOG_POS=98,
MASTER_CONNECT_RETRY=10;

START SLAVE;
SHOW SLAVE STATUS\G;

Thanks,
Vishal Vyas

No comments:

Post a Comment