Home / MySql / Configuration of MYSQL Master Slave Replication

Configuration of MYSQL Master Slave Replication

Configuration of MYSQL Master – Slave Replication

 

Environment:-

Two Server’s with MYSQL database and different hosts/nodes, Master (172.21.50.162) and Slave (10.218.86.8). Replication will be configured between these two servers as MYSQL Master – Slave replication.

On Master (172.21.50.162):-

  1. Login to the Master (172.21.50.162) environment.
  2. Start the MYSQL workbench
  3. Connect to the server using the root user and password.
  4. Use this command to check the status of the slave server at the moment and verify the following screenshots having the same value.

Query:-

mysql> select host,user from mysql.user where user=’rep_user’;

Output:-

Empty set (0.00 sec) 

  1. When the query returns null, now create the user naming ‘rep_user’ and make sure to use ‘mysql_native_password’ switch in the command

Query:-

mysql> CREATE USER ‘rep_user’@’172.21.50.162’ IDENTIFIED WITH  mysql_native_password BY ‘Docker#2023’;

Output:-

Query OK, 0 rows affected (0.01 sec)

 

 

 

  1. Crosscheck the user creation on the specified host

Query:- 

mysql> select host,user from mysql.user where user=’rep_user’;

 

Output:-

+—————+———+

| host          | user    |

+—————+———+

| 172.21.50.162 | rep_user |

+—————+———+

1 row in set (0.00 sec)

 

  1. Now grant the Replication on the created ‘rep_user’ on all the databases.

Query:-

mysql> GRANT REPLICATION SLAVE ON *.* TO ‘rep_user’@’172.21.50.162’;

Output:-

Query OK, 0 rows affected (0.01 sec)

 

  1. Use the following command to perform the checkpoint .

Query:-

mysql> FLUSH PRIVILEGES;

Output:-

Query OK, 0 rows affected (0.01 sec)

 

 

  1. Use the following command to enable a read lock on the tables in order to take a consistent backup

Query:-

mysql> FLUSH TABLES WITH READ LOCK;

Output:-

Query OK, 0 rows affected (0.01 sec)

  1. Note down the Master log Position

Query:-

mysql> SHOW MASTER STATUS;

Output:-

 

  1. Login to CMD of the server and take the backup on Master of all the databases you want to configure Replication of.

Query:-

Mysql>MYSQL –uroot –p

mysqldump -uroot -p -h<Source> –all-databases –master-data > <location><filename>.sql

 

  1. Now unlock the tables on Master.

Query:-

mysql> UNLOCK TABLES;

Output:-

Query OK, 0 rows affected (0.00 sec)

 

  1. Now Transfer Database Backup Dump File to Slave Server.

On Slave (10.218.86.8):-

            Following are the steps to be performed.

  1. Check you current Databases.

Query:-

mysql> show databases;

Output:-

+——————–+

| Database           |

+——————–+

| information_schema |

| mysql              |

| performance_schema |

| sys                |

 

  1. Restore the database dump into the slave server.

Query:-

mysql> mysql < /u01/mysql/backup/alldbdump.sql

 

  1. Now setup slave to communicate to Master, make sure to enter the same log file and log_pos noted on point ‘7’  while configuring master.

 

Query:-

mysql> CHANGE  MASTER TO MASTER_HOST=’10.142.10.181′,MASTER_USER=’rep_user’,MASTER_PASSWORD=’Docker#2021′,  MASTER_LOG_FILE=’TEST-SQL1-bin.000003′,MASTER_LOG_POS=428;

 

  1. Now start the Slave for replication.

Query:-

mysql> start slave

  1. Now check the slave status and also very the same as the screenshot below.

Query:-

mysql> show slave status

 

 

 

 

  • 5

About Abdul Khalique Siddique

In addition to my proficiency in Oracle Database, I have also specialized in Oracle E-Business Suite. I have hands-on experience in implementing, configuring, and maintaining EBS applications, enabling organizations to streamline their business processes and achieve operational efficiency. Also I have hands-on experience in Oracle Cloud Infrastructure (OCI). I have worked with OCI services such as compute, storage, networking, and database offerings, leveraging the power of the cloud to deliver scalable and cost-effective solutions. My knowledge of OCI architecture and deployment models allows me to design and implement robust and secure cloud environments for various business requirements. Furthermore, I have specialized in disaster recovery solutions for Oracle technologies. I have designed and implemented comprehensive disaster recovery strategies, including backup and recovery procedures, standby databases, and high availability configurations. My expertise in data replication, failover mechanisms, and business continuity planning ensures that organizations can quickly recover from disruptions and maintain uninterrupted operations.

Check Also

Switchover MySQL

Switchover MySQL   Source 199Replica 198 SOURCE SET GLOBAL read_only=ON; set global super_read_only=ON; show variables …

Leave a Reply