MYSQL DATABASE REPLICATION - Techforce Global | Blogs

MYSQL Database replication configuration without server downtime

Steps to setup MySQL replication with zero master downtime: 

  1. Make the below changes in the my.ini file of a master MySQL server instance, to enable binary logs:

server-id=1 (can have any unique digit) 

log-bin=mysql-bin 

  1. Restart the master instance.
  2. Create replication user in a master instance by firing below queries in master:

CREATE USER repluser@'<master IP>’ IDENTIFIED BY ‘replpass’; 

GRANT REPLICATION SLAVE ON *.* TO repluser@'<slave IP>’; 

  1. Take a full dump of Master instance. While firing command for mysqldump, include “–master-data=2” in options. It won’t lock tables. This will include one commented SQL query which will contain a master’s current log position. This type of dump is known as Point-in-Time dump.

mysqldump –skip-lock-tables –single-transaction –flush-logs –hex-blob –master-data=2 -A > ~/mysqldump.sql 

  1. Once dump is over, import it on the slave server.
  2. Find and copy the bin log position and file name in dump SQL file. It must be there on 22nd or 80th line number in dump file.
  3. Make below changes in my.ini file of slave instance:

server-id=2 (can have any unique digit) 

relay-log-index=slave-relay-bin.index 

relay-log=slave-relay-bin 

  1. If you want to make slave server read-only (for non-replication users), then add below lines in my.ini of slave instance:

read_only=1 

super_read_only=1 

  1. Restart the slave instance.
  2. Fire below query to make Master configurations in slave instance:

CHANGE MASTER TO MASTER_HOST='<master IP>’, MASTER_PORT=<master Port>, MASTER_USER='<user’s username created in #3>’, MASTER_PASSWORD='<user’s password created in #3>’, MASTER_LOG_FILE='<log file name copied from #6>’, MASTER_LOG_POS=<log file position copied from #6>; 

  1. Start the slave by firing below query in slave:

START SLAVE; 

  1. To view the slave status and verify it, fire below query in slave:

SHOW SLAVE STATUS; 

  1. Find “Slave_IO_running” and “Slave_SQL_Running” column and if everything went right, they should contain “Yes” as a value.

strip image Janmejay Gohil 4 Mar 2022


Read More Blogs

Exploring retail benefits banner 2
Exploring the top benefits of technology in Retail

In today’s technology-driven world, you should meet consumer desires by...

Sagar Shah

28 Mar 2023
FacebookTwitterLinkedInShare
The Future of Java Concurrency: Leveraging Project Loom for Unmatched Business Success

Project Loom aims to simplify concurrency in Java by introducing...

Manish Mori

6 Aug 2024
FacebookTwitterLinkedInShare

Let’s Innovate Together!

Let’s collaborate to create something amazing! We are dedicated to delivering fast and transforming solutions to address your challenges.

Connect with Us

Get in touch and bring your tech ideas to life!

USA Flag

USA

India Flag

India

Poland Flag

Poland

Skip to content