SlideShare a Scribd company logo
Reliable MySQL Using
Replication
Issac Goldstand
Mirimar Networks
www.mirimar.net
margol@beamartyr.net
What is replication?
• Allows 2 or more databases to maintain state
between them
• MySQL 3.23 and up supports asynchronous
replication
• One server acts as a master for one or more
slaves
• Slaves pull data to be replicated from server’s
binary logs and execute the relevant statements
locally
Replication basics…
• One master supports multiple slaves
• Each node on the network is assigned a unique
identifying number
• Each slave attempts to connect to the master and
fetches data to be replicated
Master
Slave
Slave
Slave
Slaves
Replication basics…
• Clients perform data modification on master
server
• INSERT, SELECT, DELETE, LOAD DATA
• EXECUTE in MySQL 5.0 and above
Master SlaveClient
DATA DATA
INSERT
INTO …
Replication basics…
• Immediately following execution of command on master,
the command is written to the local binary log
• Additionally, the master records its unique ID (to prevent
endless loops in circular replication scenarios) and the
timestamp for use with statements which use NOW(),
etc.
Master SlaveClient
DATA
DATA
INSERT
INTO …
Binary
Log
Replication basics…
• If the slave is online, the command is transmitted to the slave in
parallel (well, immediately following) to being written in the local
binary log
• Otherwise, when the slave next connects it will receive a list of all
pending statements from the master server’s binary log
• The slave’s replication IO thread stores the command in the local
relay log
Master SlaveClient
DATA
DATA
INSERT
INTO …
INSERT
INTO …
Relay
Log
Replication
Thread
Replication basics…
• Once the data is received in the slave’s relay log, the
slave SQL thread executes the command locally,
bringing the slave up-to-date with the master
• In MySQL 3.23, the IO and SQL threads were just one
thread. In later versions this was changed to boost
performance
Master SlaveClient
DATA
DATA
INSERT
INTO …
INSERT
INTO …
Relay
Log
Replication
Thread
DATA
Replication Strategies
• Load balancing – single write, distributed read
Master
Slave Slave Slave
Client (SELECT) Client (SELECT) Client (SELECT) Client (SELECT) Client (SELECT) Client (SELECT)
Client (INSERT)
Replication Strategies
• Load balancing – single write, distributed read
• Load balancing – circular read/write
MySQL
Server
MySQL
Server
MySQL
Server
Client
INSERT
INTO…
INSERT
INTO …
Client
Replication Strategies
• Load balancing – single write, distributed read
• Load balancing – circular read/write
• High availability (hot failover)
Client Master
DATA
Slave
DATA
DATADATADATA
Replication Strategies
• Load balancing – single write, distributed read
• Load balancing – circular read/write
• High availability (hot failover)
• Snapshot backups
Master
Slave
Backup with LOCK TABLES (or single transaction)
Client
INSERT / SELECT
Client
INSERT / SELECT
Simple Replication Setup
• Modify my.cnf to include a unique server-id for
each node
• On master server, ensure that log-bin (binary
logging) is enabled in my.cnf
• On slave, configure login credentials on master,
either via my.cnf or CHANGE MASTER TO
statement
• Copy initial data snapshot from master to slave
• Configure initial binary log position on slave
• Start replication with SLAVE START command
Configure master
my.cnf
-------------
[mysqld]
server-id = 1
log-bin
Configure slave
my.cnf
-------------
[mysqld]
server-id = 2
master-user = someuser
master-password = secret
master-host = ip.of.master
Initial dataset
• Binary log provides a record of all modifications to
master database starting from a fixed point: when binary
logging was activated
• If all binary logs exist on master from initial install of
MySQL, the slave(s) can use these to bring themselves
up-to-date
• Otherwise, a snapshot of the master must be taken,
using mysqldump –master-data, to provide an initial
dataset for the slave(s)
• If only MyISAM tables are used, the LOAD DATA FROM
MASTER statement may be used on the slave(s)
Configure log position
MASTER mysql> SHOW MASTER STATUS;
+---------------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------------------+----------+--------------+------------------+
| vmware-mirimar-bin.000002 | 79 | | |
+---------------------------+----------+--------------+------------------+
SLAVE mysql> CHANGE MASTER TO MASTER_LOG_FILE=‘vmware-
mirimar-bin.000002’, MASTER_LOG_POS=79;
SLAVE mysql> START SLAVE;
Using CHANGE MASTER TO
• MASTER_HOST
• MASTER_USER
• MASTER_PASSWORD
• MASTER_LOG_FILE
• MASTER_LOG_POS
Advanced CHANGE MASTER TO
• MASTER_PORT
• RELAY_LOG_FILE
• RELAY_LOG_POS
• MASTER_SSL
• SSL: CA/CAPATH/CERT/KEY/CIPHER
Confirming it works
SLAVE mysql> SHOW SLAVE STATUSG
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: vmware-mirimar
Master_User: someuser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: vmware-mirimar-bin.000002
Read_Master_Log_Pos: 79
Relay_Log_File: vmware1-mirimar-relay-bin.000002
Relay_Log_Pos: 250
Relay_Master_Log_File: vmware-mirimar-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 79
Relay_Log_Space: 250
Seconds_Behind_Master: 0
Permissions
• Slaves need REPLICATION SLAVE
permission on master for basic usage
• If LOAD TABLE FROM MASTER or LOAD
DATA FROM MASTER statements are
used, slave will also need SUPER and
RELOAD privileges
Internal Threads
• Since MySQL 4.0, replication slaves run
two threads
• IO thread continuously receives updates
from master and writes to local relay log
• SQL thread continuously executes
statements in relay log
IO thread isolation
• Isolating IO thread means that slave won’t
have to wait for long-executing statements
to finish executing before retrieving data
from master
• Also, slave will continue reading data from
master if a statement creates a data
conflict
SQL thread isolation
• SQL thread isolation allows for replication in an
environment without a continuous link between
slave and masters
• If master fails (or slave simply has no access),
the IO thread will try to reconnect endlessly
(waiting 60 seconds between attempts)
• SQL thread will continue processing relay logs
even while IO thread is unable to connect to
master
Master Thread
• Additionally, the master server runs the
Binlog Dump thread
• This thread is simply dedicated to
scanning the binary logs on the master
and sending updates to the connected
slave
• If this thread isn’t running, it means that
replication isn’t running – more accurately,
that no slaves are currently connected
Status files
• 2 status files for replication’s use
• Their use is to record the state of
replication between server shutdown and
startup
• master.info records information about the
slave’s master server
• relay-log.info records information about
the local relay logs
Information in master.info
• Master log file
• Read master log pos
• Master Host
• Master User
• Password (will not be shown in SHOW SLAVE
STATUS)
• Master Port
• Connect Retry
• In MySQL 4.1+, SSL options are stored if SSL is
used
Information in relay-log.info
• Relay log file
• Relay log pos
• Relay master-log pos
• Exec master-log pos
Backup master
• Master backups can be accomplished
with mysqldump
• Care must be taken to ensure the
following 2 special considerations:
1. Consistent snapshot of master date (via lock
tables for MyISAM or single transaction for
InnoDB)
2. Recording of binary log information, for use
on slaves (master-data)
Backup master files
• If a file-system level backup is required, care should be
taken to manually record binary log name and position
via SHOW MASTER STATUS statement.
• To ensure consistency between backup and binary log
position, the tables should be locked via FLUSH
TABLES WITH READ LOCK immediately before backup
(and SHOW MASTER STATUS)
• LEAVE THE CLIENT CONNECTED!!!
• After backup finishes, execute UNLOCK TABLES to
release the read lock
Backup slave
• Same idea as master file system backup
• Instead of recording position, it’s enough
to backup the master.info and relay-
log.info files
• Instead of acquiring global read lock, it’s
enough to STOP SLAVE before backup
and START SLAVE once backup finishes
Live demo
• Time permitting, we’ll show a short
demonstration of a simple unidirectional
replication setup
For more information
• MySQL documentation
• 5.0 documentation
http://mirror.mirimar.net/mysql/doc/refman/5.0/
• 4.1 documentation
http://mirror.mirimar.net/mysql/doc/refman/4.1/
Thank You!
For more information:
Issac Goldstand
margol@mirimar.net
http://www.beamartyr.net/
http://www.mirimar.net/

More Related Content

What's hot

Maria DB Galera Cluster for High Availability
Maria DB Galera Cluster for High AvailabilityMaria DB Galera Cluster for High Availability
Maria DB Galera Cluster for High Availability
OSSCube
 
Percona XtraDB Cluster ( Ensure high Availability )
Percona XtraDB Cluster ( Ensure high Availability )Percona XtraDB Cluster ( Ensure high Availability )
Percona XtraDB Cluster ( Ensure high Availability )
Mydbops
 
MariaDB 10.5 binary install (바이너리 설치)
MariaDB 10.5 binary install (바이너리 설치)MariaDB 10.5 binary install (바이너리 설치)
MariaDB 10.5 binary install (바이너리 설치)
NeoClova
 
Webinar: MariaDB Provides the Solution to Ease Multi-Source Replication
Webinar: MariaDB Provides the Solution to Ease Multi-Source ReplicationWebinar: MariaDB Provides the Solution to Ease Multi-Source Replication
Webinar: MariaDB Provides the Solution to Ease Multi-Source Replication
Wagner Bianchi
 
ProxySQL para mysql
ProxySQL para mysqlProxySQL para mysql
ProxySQL para mysql
Marcelo Altmann
 
Using advanced options in MariaDB Connector/J
Using advanced options in MariaDB Connector/JUsing advanced options in MariaDB Connector/J
Using advanced options in MariaDB Connector/J
MariaDB plc
 
MySQL Server Backup, Restoration, and Disaster Recovery Planning
MySQL Server Backup, Restoration, and Disaster Recovery PlanningMySQL Server Backup, Restoration, and Disaster Recovery Planning
MySQL Server Backup, Restoration, and Disaster Recovery Planning
Lenz Grimmer
 
MySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptxMySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptx
NeoClova
 
InnoDB Cluster Experience (MySQL User Camp)
InnoDB Cluster Experience (MySQL User Camp)InnoDB Cluster Experience (MySQL User Camp)
InnoDB Cluster Experience (MySQL User Camp)
Mydbops
 
M|18 Migrating from Oracle and Handling PL/SQL Stored Procedures
M|18 Migrating from Oracle and Handling PL/SQL Stored ProceduresM|18 Migrating from Oracle and Handling PL/SQL Stored Procedures
M|18 Migrating from Oracle and Handling PL/SQL Stored Procedures
MariaDB plc
 
SUSE Manager with Salt - Deploy and Config Management for MariaDB
SUSE Manager with Salt - Deploy and Config Management for MariaDBSUSE Manager with Salt - Deploy and Config Management for MariaDB
SUSE Manager with Salt - Deploy and Config Management for MariaDB
MariaDB plc
 
MySQL DBA
MySQL DBAMySQL DBA
MySQL DBA
lalit choudhary
 
InnoDB Performance Optimisation
InnoDB Performance OptimisationInnoDB Performance Optimisation
InnoDB Performance Optimisation
Mydbops
 
Performance Tuning Best Practices
Performance Tuning Best PracticesPerformance Tuning Best Practices
Performance Tuning Best Practiceswebhostingguy
 
Webinar Slides: Migrating to Galera Cluster
Webinar Slides: Migrating to Galera ClusterWebinar Slides: Migrating to Galera Cluster
Webinar Slides: Migrating to Galera ClusterSeveralnines
 
Easy MySQL Replication Setup and Troubleshooting
Easy MySQL Replication Setup and TroubleshootingEasy MySQL Replication Setup and Troubleshooting
Easy MySQL Replication Setup and Troubleshooting
Bob Burgess
 
Parallel Replication in MySQL and MariaDB
Parallel Replication in MySQL and MariaDBParallel Replication in MySQL and MariaDB
Parallel Replication in MySQL and MariaDB
Mydbops
 

What's hot (18)

Maria DB Galera Cluster for High Availability
Maria DB Galera Cluster for High AvailabilityMaria DB Galera Cluster for High Availability
Maria DB Galera Cluster for High Availability
 
Percona XtraDB Cluster ( Ensure high Availability )
Percona XtraDB Cluster ( Ensure high Availability )Percona XtraDB Cluster ( Ensure high Availability )
Percona XtraDB Cluster ( Ensure high Availability )
 
MariaDB 10.5 binary install (바이너리 설치)
MariaDB 10.5 binary install (바이너리 설치)MariaDB 10.5 binary install (바이너리 설치)
MariaDB 10.5 binary install (바이너리 설치)
 
Webinar: MariaDB Provides the Solution to Ease Multi-Source Replication
Webinar: MariaDB Provides the Solution to Ease Multi-Source ReplicationWebinar: MariaDB Provides the Solution to Ease Multi-Source Replication
Webinar: MariaDB Provides the Solution to Ease Multi-Source Replication
 
ProxySQL para mysql
ProxySQL para mysqlProxySQL para mysql
ProxySQL para mysql
 
Using advanced options in MariaDB Connector/J
Using advanced options in MariaDB Connector/JUsing advanced options in MariaDB Connector/J
Using advanced options in MariaDB Connector/J
 
MySQL Server Backup, Restoration, and Disaster Recovery Planning
MySQL Server Backup, Restoration, and Disaster Recovery PlanningMySQL Server Backup, Restoration, and Disaster Recovery Planning
MySQL Server Backup, Restoration, and Disaster Recovery Planning
 
MySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptxMySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptx
 
InnoDB Cluster Experience (MySQL User Camp)
InnoDB Cluster Experience (MySQL User Camp)InnoDB Cluster Experience (MySQL User Camp)
InnoDB Cluster Experience (MySQL User Camp)
 
M|18 Migrating from Oracle and Handling PL/SQL Stored Procedures
M|18 Migrating from Oracle and Handling PL/SQL Stored ProceduresM|18 Migrating from Oracle and Handling PL/SQL Stored Procedures
M|18 Migrating from Oracle and Handling PL/SQL Stored Procedures
 
SUSE Manager with Salt - Deploy and Config Management for MariaDB
SUSE Manager with Salt - Deploy and Config Management for MariaDBSUSE Manager with Salt - Deploy and Config Management for MariaDB
SUSE Manager with Salt - Deploy and Config Management for MariaDB
 
MySQL DBA
MySQL DBAMySQL DBA
MySQL DBA
 
InnoDB Performance Optimisation
InnoDB Performance OptimisationInnoDB Performance Optimisation
InnoDB Performance Optimisation
 
MySQL Tuning
MySQL TuningMySQL Tuning
MySQL Tuning
 
Performance Tuning Best Practices
Performance Tuning Best PracticesPerformance Tuning Best Practices
Performance Tuning Best Practices
 
Webinar Slides: Migrating to Galera Cluster
Webinar Slides: Migrating to Galera ClusterWebinar Slides: Migrating to Galera Cluster
Webinar Slides: Migrating to Galera Cluster
 
Easy MySQL Replication Setup and Troubleshooting
Easy MySQL Replication Setup and TroubleshootingEasy MySQL Replication Setup and Troubleshooting
Easy MySQL Replication Setup and Troubleshooting
 
Parallel Replication in MySQL and MariaDB
Parallel Replication in MySQL and MariaDBParallel Replication in MySQL and MariaDB
Parallel Replication in MySQL and MariaDB
 

Viewers also liked

Analyser, interpréter le jeu en badminton pour trouver des situations d'entra...
Analyser, interpréter le jeu en badminton pour trouver des situations d'entra...Analyser, interpréter le jeu en badminton pour trouver des situations d'entra...
Analyser, interpréter le jeu en badminton pour trouver des situations d'entra...
Caroline Weckerle
 
αλλαγές στην επιφάνεια της γης 3η ομάδα
αλλαγές στην επιφάνεια της γης 3η ομάδααλλαγές στην επιφάνεια της γης 3η ομάδα
αλλαγές στην επιφάνεια της γης 3η ομάδα10odskaterinis1
 
Senti Sense Pitch Deck
Senti Sense Pitch DeckSenti Sense Pitch Deck
Senti Sense Pitch Deck
Christopher Sharkey
 
[Info01]introduction
[Info01]introduction[Info01]introduction
[Info01]introductionjylee_kgit
 
Download presentation-in-powerpoint1567 (1)
Download presentation-in-powerpoint1567 (1)Download presentation-in-powerpoint1567 (1)
Download presentation-in-powerpoint1567 (1)
Indra Pratap
 
ppt file for tss turing machine
ppt file for tss turing machineppt file for tss turing machine
ppt file for tss turing machine
vishuparihar
 
YEMISBEL_RODRIGUEZ
YEMISBEL_RODRIGUEZYEMISBEL_RODRIGUEZ
YEMISBEL_RODRIGUEZ
Yemisbel Rodriguez
 
Оборудование для систем противопожарной вентиляции
Оборудование для систем противопожарной вентиляцииОборудование для систем противопожарной вентиляции
Оборудование для систем противопожарной вентиляции
АВЗ
 
Week5-8trainingweekdiarys
Week5-8trainingweekdiarysWeek5-8trainingweekdiarys
Week5-8trainingweekdiaryscameronmcivor
 
10分で分かるr言語入門ver2.8 14 0712
10分で分かるr言語入門ver2.8 14 0712 10分で分かるr言語入門ver2.8 14 0712
10分で分かるr言語入門ver2.8 14 0712 Nobuaki Oshiro
 
Maris V-SoM
Maris V-SoMMaris V-SoM
Maris V-SoM
yossib
 
Prota pai smp 13
Prota pai smp 13Prota pai smp 13
Prota pai smp 13
Maghfiroh Firoh
 
Prj 2014-101 progress-presentation-0.2.0
Prj 2014-101 progress-presentation-0.2.0Prj 2014-101 progress-presentation-0.2.0
Prj 2014-101 progress-presentation-0.2.0NepalAdz
 
CII Union Budget Analysis 2014
CII Union Budget Analysis 2014CII Union Budget Analysis 2014
CII Union Budget Analysis 2014
Confederation of Indian Industry
 
Week 4 gluttony and lust
Week 4 gluttony and lustWeek 4 gluttony and lust
Week 4 gluttony and lust
wsmithdio
 

Viewers also liked (18)

Analyser, interpréter le jeu en badminton pour trouver des situations d'entra...
Analyser, interpréter le jeu en badminton pour trouver des situations d'entra...Analyser, interpréter le jeu en badminton pour trouver des situations d'entra...
Analyser, interpréter le jeu en badminton pour trouver des situations d'entra...
 
αλλαγές στην επιφάνεια της γης 3η ομάδα
αλλαγές στην επιφάνεια της γης 3η ομάδααλλαγές στην επιφάνεια της γης 3η ομάδα
αλλαγές στην επιφάνεια της γης 3η ομάδα
 
PROPERTY MARKET IN BANGALORE
PROPERTY MARKET IN BANGALOREPROPERTY MARKET IN BANGALORE
PROPERTY MARKET IN BANGALORE
 
Senti Sense Pitch Deck
Senti Sense Pitch DeckSenti Sense Pitch Deck
Senti Sense Pitch Deck
 
[Info01]introduction
[Info01]introduction[Info01]introduction
[Info01]introduction
 
Download presentation-in-powerpoint1567 (1)
Download presentation-in-powerpoint1567 (1)Download presentation-in-powerpoint1567 (1)
Download presentation-in-powerpoint1567 (1)
 
ppt file for tss turing machine
ppt file for tss turing machineppt file for tss turing machine
ppt file for tss turing machine
 
041415-Report_FINALBOOK
041415-Report_FINALBOOK041415-Report_FINALBOOK
041415-Report_FINALBOOK
 
YEMISBEL_RODRIGUEZ
YEMISBEL_RODRIGUEZYEMISBEL_RODRIGUEZ
YEMISBEL_RODRIGUEZ
 
Оборудование для систем противопожарной вентиляции
Оборудование для систем противопожарной вентиляцииОборудование для систем противопожарной вентиляции
Оборудование для систем противопожарной вентиляции
 
Week5-8trainingweekdiarys
Week5-8trainingweekdiarysWeek5-8trainingweekdiarys
Week5-8trainingweekdiarys
 
10分で分かるr言語入門ver2.8 14 0712
10分で分かるr言語入門ver2.8 14 0712 10分で分かるr言語入門ver2.8 14 0712
10分で分かるr言語入門ver2.8 14 0712
 
Maris V-SoM
Maris V-SoMMaris V-SoM
Maris V-SoM
 
Prota pai smp 13
Prota pai smp 13Prota pai smp 13
Prota pai smp 13
 
PUSHP PRODUCT2
PUSHP PRODUCT2PUSHP PRODUCT2
PUSHP PRODUCT2
 
Prj 2014-101 progress-presentation-0.2.0
Prj 2014-101 progress-presentation-0.2.0Prj 2014-101 progress-presentation-0.2.0
Prj 2014-101 progress-presentation-0.2.0
 
CII Union Budget Analysis 2014
CII Union Budget Analysis 2014CII Union Budget Analysis 2014
CII Union Budget Analysis 2014
 
Week 4 gluttony and lust
Week 4 gluttony and lustWeek 4 gluttony and lust
Week 4 gluttony and lust
 

Similar to Download presentation531

Mysql replication @ gnugroup
Mysql replication @ gnugroupMysql replication @ gnugroup
Mysql replication @ gnugroup
Jayant Chutke
 
MySQL Replication Basics
MySQL Replication BasicsMySQL Replication Basics
MySQL Replication BasicsAbdul Manaf
 
Download presentation
Download presentationDownload presentation
Download presentationwebhostingguy
 
MySQL database replication
MySQL database replicationMySQL database replication
MySQL database replication
PoguttuezhiniVP
 
Mysql
MysqlMysql
Mysql
abhijith
 
MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016
Dave Stokes
 
MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016
Dave Stokes
 
Alibaba patches in MariaDB
Alibaba patches in MariaDBAlibaba patches in MariaDB
Alibaba patches in MariaDBLixun Peng
 
MySqL Failover by Weatherly Cloud Computing USA
MySqL Failover by Weatherly Cloud Computing USAMySqL Failover by Weatherly Cloud Computing USA
MySqL Failover by Weatherly Cloud Computing USA
Harry Gonzalez
 
MySQL Data Encryption at Rest
MySQL Data Encryption at RestMySQL Data Encryption at Rest
MySQL Data Encryption at Rest
Mydbops
 
MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016
Dave Stokes
 
MySQL Failover - Cubexs Weatherly
MySQL Failover - Cubexs WeatherlyMySQL Failover - Cubexs Weatherly
MySQL Failover - Cubexs Weatherly
Weatherly Cloud Inc.
 
MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017
Dave Stokes
 
Mysql-Basics.pptx
Mysql-Basics.pptxMysql-Basics.pptx
Mysql-Basics.pptx
ssuserf5adce
 
MySQL replication best practices 105-232-931
MySQL replication best practices 105-232-931MySQL replication best practices 105-232-931
MySQL replication best practices 105-232-931Baruch Osoveskiy
 
Mater,slave on mysql
Mater,slave on mysqlMater,slave on mysql
Mater,slave on mysqlVasudeva Rao
 
MySQL database
MySQL databaseMySQL database
MySQL database
lalit choudhary
 
MySQL highav Availability
MySQL highav AvailabilityMySQL highav Availability
MySQL highav Availability
Baruch Osoveskiy
 
ConFoo MySQL Replication Evolution : From Simple to Group Replication
ConFoo  MySQL Replication Evolution : From Simple to Group ReplicationConFoo  MySQL Replication Evolution : From Simple to Group Replication
ConFoo MySQL Replication Evolution : From Simple to Group Replication
Dave Stokes
 
User Camp High Availability Presentation
User Camp High Availability PresentationUser Camp High Availability Presentation
User Camp High Availability Presentation
sankalita chakraborty
 

Similar to Download presentation531 (20)

Mysql replication @ gnugroup
Mysql replication @ gnugroupMysql replication @ gnugroup
Mysql replication @ gnugroup
 
MySQL Replication Basics
MySQL Replication BasicsMySQL Replication Basics
MySQL Replication Basics
 
Download presentation
Download presentationDownload presentation
Download presentation
 
MySQL database replication
MySQL database replicationMySQL database replication
MySQL database replication
 
Mysql
MysqlMysql
Mysql
 
MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016
 
MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016
 
Alibaba patches in MariaDB
Alibaba patches in MariaDBAlibaba patches in MariaDB
Alibaba patches in MariaDB
 
MySqL Failover by Weatherly Cloud Computing USA
MySqL Failover by Weatherly Cloud Computing USAMySqL Failover by Weatherly Cloud Computing USA
MySqL Failover by Weatherly Cloud Computing USA
 
MySQL Data Encryption at Rest
MySQL Data Encryption at RestMySQL Data Encryption at Rest
MySQL Data Encryption at Rest
 
MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016
 
MySQL Failover - Cubexs Weatherly
MySQL Failover - Cubexs WeatherlyMySQL Failover - Cubexs Weatherly
MySQL Failover - Cubexs Weatherly
 
MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017
 
Mysql-Basics.pptx
Mysql-Basics.pptxMysql-Basics.pptx
Mysql-Basics.pptx
 
MySQL replication best practices 105-232-931
MySQL replication best practices 105-232-931MySQL replication best practices 105-232-931
MySQL replication best practices 105-232-931
 
Mater,slave on mysql
Mater,slave on mysqlMater,slave on mysql
Mater,slave on mysql
 
MySQL database
MySQL databaseMySQL database
MySQL database
 
MySQL highav Availability
MySQL highav AvailabilityMySQL highav Availability
MySQL highav Availability
 
ConFoo MySQL Replication Evolution : From Simple to Group Replication
ConFoo  MySQL Replication Evolution : From Simple to Group ReplicationConFoo  MySQL Replication Evolution : From Simple to Group Replication
ConFoo MySQL Replication Evolution : From Simple to Group Replication
 
User Camp High Availability Presentation
User Camp High Availability PresentationUser Camp High Availability Presentation
User Camp High Availability Presentation
 

Recently uploaded

Search Disrupted Google’s Leaked Documents Rock the SEO World.pdf
Search Disrupted Google’s Leaked Documents Rock the SEO World.pdfSearch Disrupted Google’s Leaked Documents Rock the SEO World.pdf
Search Disrupted Google’s Leaked Documents Rock the SEO World.pdf
Arihant Webtech Pvt. Ltd
 
Buy Verified PayPal Account | Buy Google 5 Star Reviews
Buy Verified PayPal Account | Buy Google 5 Star ReviewsBuy Verified PayPal Account | Buy Google 5 Star Reviews
Buy Verified PayPal Account | Buy Google 5 Star Reviews
usawebmarket
 
Cree_Rey_BrandIdentityKit.PDF_PersonalBd
Cree_Rey_BrandIdentityKit.PDF_PersonalBdCree_Rey_BrandIdentityKit.PDF_PersonalBd
Cree_Rey_BrandIdentityKit.PDF_PersonalBd
creerey
 
Sustainability: Balancing the Environment, Equity & Economy
Sustainability: Balancing the Environment, Equity & EconomySustainability: Balancing the Environment, Equity & Economy
Sustainability: Balancing the Environment, Equity & Economy
Operational Excellence Consulting
 
Introduction to Amazon company 111111111111
Introduction to Amazon company 111111111111Introduction to Amazon company 111111111111
Introduction to Amazon company 111111111111
zoyaansari11365
 
Training my puppy and implementation in this story
Training my puppy and implementation in this storyTraining my puppy and implementation in this story
Training my puppy and implementation in this story
WilliamRodrigues148
 
Brand Analysis for an artist named Struan
Brand Analysis for an artist named StruanBrand Analysis for an artist named Struan
Brand Analysis for an artist named Struan
sarahvanessa51503
 
Affordable Stationery Printing Services in Jaipur | Navpack n Print
Affordable Stationery Printing Services in Jaipur | Navpack n PrintAffordable Stationery Printing Services in Jaipur | Navpack n Print
Affordable Stationery Printing Services in Jaipur | Navpack n Print
Navpack & Print
 
Auditing study material for b.com final year students
Auditing study material for b.com final year  studentsAuditing study material for b.com final year  students
Auditing study material for b.com final year students
narasimhamurthyh4
 
Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...
Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...
Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...
Lviv Startup Club
 
LA HUG - Video Testimonials with Chynna Morgan - June 2024
LA HUG - Video Testimonials with Chynna Morgan - June 2024LA HUG - Video Testimonials with Chynna Morgan - June 2024
LA HUG - Video Testimonials with Chynna Morgan - June 2024
Lital Barkan
 
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.docBài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
daothibichhang1
 
Business Valuation Principles for Entrepreneurs
Business Valuation Principles for EntrepreneursBusiness Valuation Principles for Entrepreneurs
Business Valuation Principles for Entrepreneurs
Ben Wann
 
VAT Registration Outlined In UAE: Benefits and Requirements
VAT Registration Outlined In UAE: Benefits and RequirementsVAT Registration Outlined In UAE: Benefits and Requirements
VAT Registration Outlined In UAE: Benefits and Requirements
uae taxgpt
 
Cracking the Workplace Discipline Code Main.pptx
Cracking the Workplace Discipline Code Main.pptxCracking the Workplace Discipline Code Main.pptx
Cracking the Workplace Discipline Code Main.pptx
Workforce Group
 
The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...
Adam Smith
 
ikea_woodgreen_petscharity_dog-alogue_digital.pdf
ikea_woodgreen_petscharity_dog-alogue_digital.pdfikea_woodgreen_petscharity_dog-alogue_digital.pdf
ikea_woodgreen_petscharity_dog-alogue_digital.pdf
agatadrynko
 
Discover the innovative and creative projects that highlight my journey throu...
Discover the innovative and creative projects that highlight my journey throu...Discover the innovative and creative projects that highlight my journey throu...
Discover the innovative and creative projects that highlight my journey throu...
dylandmeas
 
amptalk_RecruitingDeck_english_2024.06.05
amptalk_RecruitingDeck_english_2024.06.05amptalk_RecruitingDeck_english_2024.06.05
amptalk_RecruitingDeck_english_2024.06.05
marketing317746
 
Agency Managed Advisory Board As a Solution To Career Path Defining Business ...
Agency Managed Advisory Board As a Solution To Career Path Defining Business ...Agency Managed Advisory Board As a Solution To Career Path Defining Business ...
Agency Managed Advisory Board As a Solution To Career Path Defining Business ...
Boris Ziegler
 

Recently uploaded (20)

Search Disrupted Google’s Leaked Documents Rock the SEO World.pdf
Search Disrupted Google’s Leaked Documents Rock the SEO World.pdfSearch Disrupted Google’s Leaked Documents Rock the SEO World.pdf
Search Disrupted Google’s Leaked Documents Rock the SEO World.pdf
 
Buy Verified PayPal Account | Buy Google 5 Star Reviews
Buy Verified PayPal Account | Buy Google 5 Star ReviewsBuy Verified PayPal Account | Buy Google 5 Star Reviews
Buy Verified PayPal Account | Buy Google 5 Star Reviews
 
Cree_Rey_BrandIdentityKit.PDF_PersonalBd
Cree_Rey_BrandIdentityKit.PDF_PersonalBdCree_Rey_BrandIdentityKit.PDF_PersonalBd
Cree_Rey_BrandIdentityKit.PDF_PersonalBd
 
Sustainability: Balancing the Environment, Equity & Economy
Sustainability: Balancing the Environment, Equity & EconomySustainability: Balancing the Environment, Equity & Economy
Sustainability: Balancing the Environment, Equity & Economy
 
Introduction to Amazon company 111111111111
Introduction to Amazon company 111111111111Introduction to Amazon company 111111111111
Introduction to Amazon company 111111111111
 
Training my puppy and implementation in this story
Training my puppy and implementation in this storyTraining my puppy and implementation in this story
Training my puppy and implementation in this story
 
Brand Analysis for an artist named Struan
Brand Analysis for an artist named StruanBrand Analysis for an artist named Struan
Brand Analysis for an artist named Struan
 
Affordable Stationery Printing Services in Jaipur | Navpack n Print
Affordable Stationery Printing Services in Jaipur | Navpack n PrintAffordable Stationery Printing Services in Jaipur | Navpack n Print
Affordable Stationery Printing Services in Jaipur | Navpack n Print
 
Auditing study material for b.com final year students
Auditing study material for b.com final year  studentsAuditing study material for b.com final year  students
Auditing study material for b.com final year students
 
Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...
Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...
Evgen Osmak: Methods of key project parameters estimation: from the shaman-in...
 
LA HUG - Video Testimonials with Chynna Morgan - June 2024
LA HUG - Video Testimonials with Chynna Morgan - June 2024LA HUG - Video Testimonials with Chynna Morgan - June 2024
LA HUG - Video Testimonials with Chynna Morgan - June 2024
 
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.docBài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
 
Business Valuation Principles for Entrepreneurs
Business Valuation Principles for EntrepreneursBusiness Valuation Principles for Entrepreneurs
Business Valuation Principles for Entrepreneurs
 
VAT Registration Outlined In UAE: Benefits and Requirements
VAT Registration Outlined In UAE: Benefits and RequirementsVAT Registration Outlined In UAE: Benefits and Requirements
VAT Registration Outlined In UAE: Benefits and Requirements
 
Cracking the Workplace Discipline Code Main.pptx
Cracking the Workplace Discipline Code Main.pptxCracking the Workplace Discipline Code Main.pptx
Cracking the Workplace Discipline Code Main.pptx
 
The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...
 
ikea_woodgreen_petscharity_dog-alogue_digital.pdf
ikea_woodgreen_petscharity_dog-alogue_digital.pdfikea_woodgreen_petscharity_dog-alogue_digital.pdf
ikea_woodgreen_petscharity_dog-alogue_digital.pdf
 
Discover the innovative and creative projects that highlight my journey throu...
Discover the innovative and creative projects that highlight my journey throu...Discover the innovative and creative projects that highlight my journey throu...
Discover the innovative and creative projects that highlight my journey throu...
 
amptalk_RecruitingDeck_english_2024.06.05
amptalk_RecruitingDeck_english_2024.06.05amptalk_RecruitingDeck_english_2024.06.05
amptalk_RecruitingDeck_english_2024.06.05
 
Agency Managed Advisory Board As a Solution To Career Path Defining Business ...
Agency Managed Advisory Board As a Solution To Career Path Defining Business ...Agency Managed Advisory Board As a Solution To Career Path Defining Business ...
Agency Managed Advisory Board As a Solution To Career Path Defining Business ...
 

Download presentation531

  • 1. Reliable MySQL Using Replication Issac Goldstand Mirimar Networks www.mirimar.net margol@beamartyr.net
  • 2. What is replication? • Allows 2 or more databases to maintain state between them • MySQL 3.23 and up supports asynchronous replication • One server acts as a master for one or more slaves • Slaves pull data to be replicated from server’s binary logs and execute the relevant statements locally
  • 3. Replication basics… • One master supports multiple slaves • Each node on the network is assigned a unique identifying number • Each slave attempts to connect to the master and fetches data to be replicated Master Slave Slave Slave Slaves
  • 4. Replication basics… • Clients perform data modification on master server • INSERT, SELECT, DELETE, LOAD DATA • EXECUTE in MySQL 5.0 and above Master SlaveClient DATA DATA INSERT INTO …
  • 5. Replication basics… • Immediately following execution of command on master, the command is written to the local binary log • Additionally, the master records its unique ID (to prevent endless loops in circular replication scenarios) and the timestamp for use with statements which use NOW(), etc. Master SlaveClient DATA DATA INSERT INTO … Binary Log
  • 6. Replication basics… • If the slave is online, the command is transmitted to the slave in parallel (well, immediately following) to being written in the local binary log • Otherwise, when the slave next connects it will receive a list of all pending statements from the master server’s binary log • The slave’s replication IO thread stores the command in the local relay log Master SlaveClient DATA DATA INSERT INTO … INSERT INTO … Relay Log Replication Thread
  • 7. Replication basics… • Once the data is received in the slave’s relay log, the slave SQL thread executes the command locally, bringing the slave up-to-date with the master • In MySQL 3.23, the IO and SQL threads were just one thread. In later versions this was changed to boost performance Master SlaveClient DATA DATA INSERT INTO … INSERT INTO … Relay Log Replication Thread DATA
  • 8. Replication Strategies • Load balancing – single write, distributed read Master Slave Slave Slave Client (SELECT) Client (SELECT) Client (SELECT) Client (SELECT) Client (SELECT) Client (SELECT) Client (INSERT)
  • 9. Replication Strategies • Load balancing – single write, distributed read • Load balancing – circular read/write MySQL Server MySQL Server MySQL Server Client INSERT INTO… INSERT INTO … Client
  • 10. Replication Strategies • Load balancing – single write, distributed read • Load balancing – circular read/write • High availability (hot failover) Client Master DATA Slave DATA DATADATADATA
  • 11. Replication Strategies • Load balancing – single write, distributed read • Load balancing – circular read/write • High availability (hot failover) • Snapshot backups Master Slave Backup with LOCK TABLES (or single transaction) Client INSERT / SELECT Client INSERT / SELECT
  • 12. Simple Replication Setup • Modify my.cnf to include a unique server-id for each node • On master server, ensure that log-bin (binary logging) is enabled in my.cnf • On slave, configure login credentials on master, either via my.cnf or CHANGE MASTER TO statement • Copy initial data snapshot from master to slave • Configure initial binary log position on slave • Start replication with SLAVE START command
  • 14. Configure slave my.cnf ------------- [mysqld] server-id = 2 master-user = someuser master-password = secret master-host = ip.of.master
  • 15. Initial dataset • Binary log provides a record of all modifications to master database starting from a fixed point: when binary logging was activated • If all binary logs exist on master from initial install of MySQL, the slave(s) can use these to bring themselves up-to-date • Otherwise, a snapshot of the master must be taken, using mysqldump –master-data, to provide an initial dataset for the slave(s) • If only MyISAM tables are used, the LOAD DATA FROM MASTER statement may be used on the slave(s)
  • 16. Configure log position MASTER mysql> SHOW MASTER STATUS; +---------------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +---------------------------+----------+--------------+------------------+ | vmware-mirimar-bin.000002 | 79 | | | +---------------------------+----------+--------------+------------------+ SLAVE mysql> CHANGE MASTER TO MASTER_LOG_FILE=‘vmware- mirimar-bin.000002’, MASTER_LOG_POS=79; SLAVE mysql> START SLAVE;
  • 17. Using CHANGE MASTER TO • MASTER_HOST • MASTER_USER • MASTER_PASSWORD • MASTER_LOG_FILE • MASTER_LOG_POS
  • 18. Advanced CHANGE MASTER TO • MASTER_PORT • RELAY_LOG_FILE • RELAY_LOG_POS • MASTER_SSL • SSL: CA/CAPATH/CERT/KEY/CIPHER
  • 19. Confirming it works SLAVE mysql> SHOW SLAVE STATUSG *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: vmware-mirimar Master_User: someuser Master_Port: 3306 Connect_Retry: 60 Master_Log_File: vmware-mirimar-bin.000002 Read_Master_Log_Pos: 79 Relay_Log_File: vmware1-mirimar-relay-bin.000002 Relay_Log_Pos: 250 Relay_Master_Log_File: vmware-mirimar-bin.000002 Slave_IO_Running: Yes Slave_SQL_Running: Yes Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 79 Relay_Log_Space: 250 Seconds_Behind_Master: 0
  • 20. Permissions • Slaves need REPLICATION SLAVE permission on master for basic usage • If LOAD TABLE FROM MASTER or LOAD DATA FROM MASTER statements are used, slave will also need SUPER and RELOAD privileges
  • 21. Internal Threads • Since MySQL 4.0, replication slaves run two threads • IO thread continuously receives updates from master and writes to local relay log • SQL thread continuously executes statements in relay log
  • 22. IO thread isolation • Isolating IO thread means that slave won’t have to wait for long-executing statements to finish executing before retrieving data from master • Also, slave will continue reading data from master if a statement creates a data conflict
  • 23. SQL thread isolation • SQL thread isolation allows for replication in an environment without a continuous link between slave and masters • If master fails (or slave simply has no access), the IO thread will try to reconnect endlessly (waiting 60 seconds between attempts) • SQL thread will continue processing relay logs even while IO thread is unable to connect to master
  • 24. Master Thread • Additionally, the master server runs the Binlog Dump thread • This thread is simply dedicated to scanning the binary logs on the master and sending updates to the connected slave • If this thread isn’t running, it means that replication isn’t running – more accurately, that no slaves are currently connected
  • 25. Status files • 2 status files for replication’s use • Their use is to record the state of replication between server shutdown and startup • master.info records information about the slave’s master server • relay-log.info records information about the local relay logs
  • 26. Information in master.info • Master log file • Read master log pos • Master Host • Master User • Password (will not be shown in SHOW SLAVE STATUS) • Master Port • Connect Retry • In MySQL 4.1+, SSL options are stored if SSL is used
  • 27. Information in relay-log.info • Relay log file • Relay log pos • Relay master-log pos • Exec master-log pos
  • 28. Backup master • Master backups can be accomplished with mysqldump • Care must be taken to ensure the following 2 special considerations: 1. Consistent snapshot of master date (via lock tables for MyISAM or single transaction for InnoDB) 2. Recording of binary log information, for use on slaves (master-data)
  • 29. Backup master files • If a file-system level backup is required, care should be taken to manually record binary log name and position via SHOW MASTER STATUS statement. • To ensure consistency between backup and binary log position, the tables should be locked via FLUSH TABLES WITH READ LOCK immediately before backup (and SHOW MASTER STATUS) • LEAVE THE CLIENT CONNECTED!!! • After backup finishes, execute UNLOCK TABLES to release the read lock
  • 30. Backup slave • Same idea as master file system backup • Instead of recording position, it’s enough to backup the master.info and relay- log.info files • Instead of acquiring global read lock, it’s enough to STOP SLAVE before backup and START SLAVE once backup finishes
  • 31. Live demo • Time permitting, we’ll show a short demonstration of a simple unidirectional replication setup
  • 32. For more information • MySQL documentation • 5.0 documentation http://mirror.mirimar.net/mysql/doc/refman/5.0/ • 4.1 documentation http://mirror.mirimar.net/mysql/doc/refman/4.1/
  • 33. Thank You! For more information: Issac Goldstand margol@mirimar.net http://www.beamartyr.net/ http://www.mirimar.net/