100% found this document useful (1 vote)
102 views4 pages

In My Case: Master - Slave Replication Step by Step

This document provides steps to configure master-slave replication between two MySQL database servers with IPs 192.168.172.133 and 192.168.172.134. The steps include creating a replication user on the master, granting privileges, locking tables, backing up the "replicadb" database, transferring the backup to the slave, restoring the database on the slave, and obtaining the binlog file name and position from the master to begin replication on the slave. Testing involves creating a new table on the master and verifying it is replicated to the slave.

Uploaded by

Mercedez Benz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
102 views4 pages

In My Case: Master - Slave Replication Step by Step

This document provides steps to configure master-slave replication between two MySQL database servers with IPs 192.168.172.133 and 192.168.172.134. The steps include creating a replication user on the master, granting privileges, locking tables, backing up the "replicadb" database, transferring the backup to the slave, restoring the database on the slave, and obtaining the binlog file name and position from the master to begin replication on the slave. Testing involves creating a new table on the master and verifying it is replicated to the slave.

Uploaded by

Mercedez Benz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

MASTER -SLAVE REPLICATION STEP BY STEP

In my Case

Master IP=192.168.172.133

SLAVE IP=192.168.172.134

Configuration of MASTER SIDE

#edit the my.cnf file by using vi /etc/my.cnf

Restart mysqld #systemctl restart mysqld

#mysql -uroot -p

Create replication user on Master db server, slave will use this user to connect to master db.
mysql> create user 'repli'@'192.168.172.134' IDENTIFIED WITH mysql_native_password BY 'Admin123!';

mysql> grant replication slave on *.* to 'repli'@'192.168.172.134';


mysql> flush privileges;
Create replicated database for testing and grant all privileges for this database.

mysql> create database replicadb;

mysql> use replicadb;

mysql> CREATE TABLE replicatb ( id int unsigned not null auto_increment,


name varchar(20) not null, constraint pk_example primary key (id) );

mysql> GRANT ALL PRIVILEGES ON replicadb.* to 'repli'@'192.168.172.134';


Lock database tables then backup database and transfer it to slave for restoring later.
# mysqldump -u root -p replicadb > replicadb.sql
Enter password:

#scp replicadb.sql [email protected]:/tmp

after moving .sql file unlock tables in mysql on MASTER SIDE

Edited by #Faisal Hushaim

Configuration of Slave Side

#edit the my.cnf file by using vi /etc/my.cnf


Now restart mysql server as below in slave

#systemctl restart mysqld

Restore database in slave


Create the database before importing the data

mysql> create database replicadb;

# cat replicadb.sql | mysql -u root -p replicadb

On master database you run the command “show master status\G” to get binlog file name and
binlog position

Now we start the replication process in slave server by login into MySQL server at slave with
root and stop slave.
TESTING

To Test the Configuration Create The Table on MASTER SIDE;

Check WHETHER IT IS TRANSFER TO ON SLAVE SIDE:

#Edited by Faisal Hushaim

You might also like