SlideShare a Scribd company logo
3
Most read
4
Most read
7
Most read
Intro to MySQL Master
Slave Replication
Satej Kumar Sahu
Mindfire Solutions
Contents
• What is Replication?
• Concept of Master and Slave
• Advantages of Replication
• Methods of Replication
• How event based replication works?
• Demo setup of master slave replication in MySQL
• Code/config setup from the start for allowing app level support for master-slave setups later
• Scenarios best for this setup/strategy
• Conclusion
• References
What is Replication?
• Replication enables data from one MySQL
database server (the master) to be copied to one or
more MySQL database servers (the slaves).
• By default asynchronous.
Concept of Master and Slave
Advantages of Replication
• Scale-out solutions
• Data security
• Analytics
• Long-distance data distribution
Methods of Replication
• Traditional method based on replicating events
from the master's binary log, and requires the log
files and positions in them to be synchronized
between master and slave.
- Types of events: Row based (default) or statement
based or mixed type.
• Newer method based on global transaction
identifiers (GTIDs) which is transactional.
How event based
Replication works?
Demo setup of master slave
replication in MySQL
• Two AWS instances with port 3306 open for mysql
on master instance.
Code/config setup from the start for
allowing app level support for master-slave
setups later
• Database access layer code should have been properly abstracted/modularized
• safe_writer_connect()
safe_reader_connect()
safe_reader_statement()
safe_writer_statement()
• Important thing is to have a unified interface for connecting for reads, connecting for
writes, doing a read, and doing a write.
• May be a painful and scary process at first. The code is much easier to maintain, and
adding troubleshooting options is trivial. You need modify only one or two functions;
for example, to log how long each statement took, or which statement among those
issued gave you an error.
• Also, you can create a user for write only and read only privileges to connect to master
and slave for added separation of concern layer.
Scenarios best for this
setup/strategy
• Most of the cases you would not need it. A good designed, optimised, normalized
database would not require it normally.
• MySQL replication is most beneficial for a system that processes frequent reads and
infrequent or low number of writes/updates.
• Answering the following questions should help you decide whether and by how much
replication will improve the performance of your system
- read/write ratio on your system?
- How much more write load can one server handle if you reduce the reads?
- For how many slaves do you have bandwidth available on your network?
• Examples:
- Ecommerce sites
- Newspaper sites
- Online library sites
- Blogging sites
• Browsing happens much in comparison to writes.
Conclusion
• In most of the case, given good database design
and optimisations and use of indexes, you would
not need replication in most of the cases.
• But if you need to scale out due to large number of
reads, you should go for it :)
References
• http://dev.mysql.com/doc/refman/5.7/en/replication.html
• https://www.percona.com/blog/2013/01/09/how-does-
mysql-replication-really-work/
• https://dev.mysql.com/doc/refman/5.7/en/faqs-
replication.html
• https://dev.mysql.com/doc/refman/5.7/en/faqs-
replication.html#faq-replication-replication-how-benefits-
me
any?
Thank You :)

More Related Content

PDF
The InnoDB Storage Engine for MySQL
PPTX
MySQL Architecture and Engine
PDF
MySQL Backup & Recovery
PDF
MySQL Data Encryption at Rest
PDF
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
PDF
MySQL GTID Concepts, Implementation and troubleshooting
PPTX
ProxySQL for MySQL
PDF
MySQL InnoDB Cluster - Group Replication
The InnoDB Storage Engine for MySQL
MySQL Architecture and Engine
MySQL Backup & Recovery
MySQL Data Encryption at Rest
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
MySQL GTID Concepts, Implementation and troubleshooting
ProxySQL for MySQL
MySQL InnoDB Cluster - Group Replication

What's hot (20)

PPTX
Mysql data replication
PDF
MySQL Advanced Administrator 2021 - 네오클로바
PDF
MariaDB Performance Tuning and Optimization
PDF
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
PDF
Best practices for MySQL High Availability
PDF
Redo log improvements MYSQL 8.0
PPTX
MySQL_MariaDB-성능개선-202201.pptx
PDF
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
PDF
ProxySQL High Avalability and Configuration Management Overview
PPTX
Running MariaDB in multiple data centers
PDF
MongoDB Database Replication
PDF
MariaDB MaxScale
PDF
The Full MySQL and MariaDB Parallel Replication Tutorial
PDF
MySQL High Availability Solutions
PDF
MySQL Administrator 2021 - 네오클로바
PDF
M|18 Architectural Overview: MariaDB MaxScale
PDF
Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison
PDF
MySQL Performance Schema in Action
PDF
InnoDb Vs NDB Cluster
PDF
Optimizing MariaDB for maximum performance
Mysql data replication
MySQL Advanced Administrator 2021 - 네오클로바
MariaDB Performance Tuning and Optimization
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
Best practices for MySQL High Availability
Redo log improvements MYSQL 8.0
MySQL_MariaDB-성능개선-202201.pptx
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
ProxySQL High Avalability and Configuration Management Overview
Running MariaDB in multiple data centers
MongoDB Database Replication
MariaDB MaxScale
The Full MySQL and MariaDB Parallel Replication Tutorial
MySQL High Availability Solutions
MySQL Administrator 2021 - 네오클로바
M|18 Architectural Overview: MariaDB MaxScale
Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison
MySQL Performance Schema in Action
InnoDb Vs NDB Cluster
Optimizing MariaDB for maximum performance
Ad

Similar to Intro to MySQL Master Slave Replication (20)

ODP
Mysql
PPTX
MySqL Failover by Weatherly Cloud Computing USA
PPT
MySQL Replication Basics
ODP
MySQL 101 PHPTek 2017
PDF
Mysql Replication Excerpt 5.1 En
PPTX
MySQL Failover - Cubexs Weatherly
PDF
MySQL Replication Update -- Zendcon 2016
PDF
MySQL Replication Basics -Ohio Linux Fest 2016
DOCX
Mater,slave on mysql
ODP
Mysql S&M
PDF
MySQL database replication
DOCX
Master master vs master-slave database
PPT
Download presentation
PPT
Download presentation531
ODP
Database Replication
PPTX
MySQL Replication Overview -- PHPTek 2016
PDF
Evolution of MySQL Parallel Replication
ODP
Mysql Replication 4 Idiots
PPTX
MySQL Replication Evolution -- Confoo Montreal 2017
PDF
MySQL Scalability and Reliability for Replicated Environment
Mysql
MySqL Failover by Weatherly Cloud Computing USA
MySQL Replication Basics
MySQL 101 PHPTek 2017
Mysql Replication Excerpt 5.1 En
MySQL Failover - Cubexs Weatherly
MySQL Replication Update -- Zendcon 2016
MySQL Replication Basics -Ohio Linux Fest 2016
Mater,slave on mysql
Mysql S&M
MySQL database replication
Master master vs master-slave database
Download presentation
Download presentation531
Database Replication
MySQL Replication Overview -- PHPTek 2016
Evolution of MySQL Parallel Replication
Mysql Replication 4 Idiots
MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Scalability and Reliability for Replicated Environment
Ad

Recently uploaded (20)

PPT
Introduction Database Management System for Course Database
PDF
Digital Strategies for Manufacturing Companies
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
AI in Product Development-omnex systems
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
top salesforce developer skills in 2025.pdf
PDF
System and Network Administraation Chapter 3
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Introduction Database Management System for Course Database
Digital Strategies for Manufacturing Companies
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
AI in Product Development-omnex systems
Operating system designcfffgfgggggggvggggggggg
Odoo POS Development Services by CandidRoot Solutions
Which alternative to Crystal Reports is best for small or large businesses.pdf
ISO 45001 Occupational Health and Safety Management System
top salesforce developer skills in 2025.pdf
System and Network Administraation Chapter 3
Softaken Excel to vCard Converter Software.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Upgrade and Innovation Strategies for SAP ERP Customers
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Understanding Forklifts - TECH EHS Solution
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Design an Analysis of Algorithms I-SECS-1021-03
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx

Intro to MySQL Master Slave Replication

  • 1. Intro to MySQL Master Slave Replication Satej Kumar Sahu Mindfire Solutions
  • 2. Contents • What is Replication? • Concept of Master and Slave • Advantages of Replication • Methods of Replication • How event based replication works? • Demo setup of master slave replication in MySQL • Code/config setup from the start for allowing app level support for master-slave setups later • Scenarios best for this setup/strategy • Conclusion • References
  • 3. What is Replication? • Replication enables data from one MySQL database server (the master) to be copied to one or more MySQL database servers (the slaves). • By default asynchronous.
  • 4. Concept of Master and Slave
  • 5. Advantages of Replication • Scale-out solutions • Data security • Analytics • Long-distance data distribution
  • 6. Methods of Replication • Traditional method based on replicating events from the master's binary log, and requires the log files and positions in them to be synchronized between master and slave. - Types of events: Row based (default) or statement based or mixed type. • Newer method based on global transaction identifiers (GTIDs) which is transactional.
  • 8. Demo setup of master slave replication in MySQL • Two AWS instances with port 3306 open for mysql on master instance.
  • 9. Code/config setup from the start for allowing app level support for master-slave setups later • Database access layer code should have been properly abstracted/modularized • safe_writer_connect() safe_reader_connect() safe_reader_statement() safe_writer_statement() • Important thing is to have a unified interface for connecting for reads, connecting for writes, doing a read, and doing a write. • May be a painful and scary process at first. The code is much easier to maintain, and adding troubleshooting options is trivial. You need modify only one or two functions; for example, to log how long each statement took, or which statement among those issued gave you an error. • Also, you can create a user for write only and read only privileges to connect to master and slave for added separation of concern layer.
  • 10. Scenarios best for this setup/strategy • Most of the cases you would not need it. A good designed, optimised, normalized database would not require it normally. • MySQL replication is most beneficial for a system that processes frequent reads and infrequent or low number of writes/updates. • Answering the following questions should help you decide whether and by how much replication will improve the performance of your system - read/write ratio on your system? - How much more write load can one server handle if you reduce the reads? - For how many slaves do you have bandwidth available on your network? • Examples: - Ecommerce sites - Newspaper sites - Online library sites - Blogging sites • Browsing happens much in comparison to writes.
  • 11. Conclusion • In most of the case, given good database design and optimisations and use of indexes, you would not need replication in most of the cases. • But if you need to scale out due to large number of reads, you should go for it :)
  • 12. References • http://dev.mysql.com/doc/refman/5.7/en/replication.html • https://www.percona.com/blog/2013/01/09/how-does- mysql-replication-really-work/ • https://dev.mysql.com/doc/refman/5.7/en/faqs- replication.html • https://dev.mysql.com/doc/refman/5.7/en/faqs- replication.html#faq-replication-replication-how-benefits- me
  • 13. any?