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:
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