SlideShare a Scribd company logo
baruch osoveskiy
baruch@dbaces.com
 Baruch osoveskiy
 Senior Consultant in dbaces.com
 Linux-Unix SYSADMIN form 1997
 DBA on Oracle and MySQL Since 2000
 Working with unstructured Data (“big data”)
since 2000 like text and spatial
 Oracle and Microsoft Partners
 Oracle Aces and Ace Directors
 What we do
◦ Remote DBA services
◦ Database consulting and projects
◦ Oracle identity and access management
◦ Training
 Platforms
◦ Oracle DB
◦ Microsoft SQL Server
◦ MySQL
◦ PostgreSQL
MySQL replication best practices 105-232-931
 One webinar each week
 Webinar recording will be available on site a few
days after webinar
 Check our webinars schedule @
http://www.dbaces.com/training/upcoming-webinars
 subscribe to get updates @ www.dbaces.com
 MySQL replication Introduction
 New features in MySQL 5.6 replication
 How to Create MySQL replication with hot-
backups
 How To monitor MySQL replication
Master SlaveNETWORK
Master SlaveNETWORK
Slave
Slave
Slave
Slave
• High availability – can promote
slave to master
• Scale Out – add multiple read slaves
• Analytics – can run Analytics on live
data.
• Backup – run cold backup on slave.
• For DEV and Pre-Prod
Replication Formats
• SBR - Statement Based Replication
• Nondeterministic function problem
• RBR - Row Based Replication
• High network usage
• Higher IO usage
• Mixed Mode
Not safe Nondeterministic function
FOUND_ROWS(), GET_LOCK(), IS_FREE_LOCK(),
IS_USED_LOCK(), LOAD_FILE(),
MASTER_POS_WAIT(), RELEASE_LOCK(),
ROW_COUNT(), SESSION_USER(), SLEEP(),
SYSDATE(), SYSTEM_USER(), USER(), UUID(),
and UUID_SHORT().
Where the Changes Stored
• Binary Log – Master (blue-bin.000002)
• Relay Log – Slave (white-relay-bin.000003)
Replication Threads
• Master Server
• Binlog Dump Thread
• Slave Server
• IO Thread
• SQL Thread
Method of Sending the Data (Replication Type)
• Asynchronous Replication
• Semi-Synchronous Replication (5.5 )
Master
TRX1
TRX2
TRX3
.
Slave
1
Binary
log
DML
+
COMMIT
Binlog Dump Thread
Master
TRX1
TRX2
TRX3
.
Slave
1
2
Binary
log
IO Thread
DML
+
COMMIT
Master
TRX1
TRX2
TRX3
.
Slave
TRX1
TRX2
TRX3
.
1
2
3
Binary
log
Relay
Log
IO Thread
DML
+
COMMIT
Master
TRX1
TRX2
TRX3
.
Slave
TRX1
TRX2
TRX3
.
1
2
3
4
Binary
log
Relay
Log
IO Thread
SQL Thread
DML
+
COMMIT
Master
TRX1
TRX2
TRX3
.
Slave
TRX1
TRX2
TRX3
.
1
2
3
4
5
Binary
log
Relay
Log
IO Thread
SQL Thread
DML
+
COMMIT
Pros
• Fast
• slave can be disconnected
Cons
• Potential loss of transactions and data integrity
Master
TRX1
TRX2
TRX3
.
Slave
1
Binary
log
DML
Binlog Dump Thread
Master
TRX1
TRX2
TRX3
.
Slave
1
Binary
log
DML
IO Thread
Master
TRX1
TRX2
TRX3
.
Slave
1
Binary
log
DML
IO Thread
2
3
4
IO Thread
TRX1
TRX2
TRX3
.
Relay
Log
Master
TRX1
TRX2
TRX3
.
Slave
TRX1
TRX2
TRX3
.
1
2
3
4
Binary
log
Relay
Log
IO Thread
IO Thread
DML
Master
TRX1
TRX2
TRX3
.
Slave
TRX1
TRX2
TRX3
.
1
2
3
4
Binary
log
Relay
Log
IO Thread
IO Thread
DML
COMMIT
Master
TRX1
TRX2
TRX3
.
Slave
TRX1
TRX2
TRX3
.
1
2
3
4
Binary
log
Relay
Log
IO Thread
IO Thread
DML
COMMIT
5SQL Thread
Pros
• data integrity
• Commit ensure the transaction will copy to
slave
Cons
• Performance Implications
• The transaction need to Wait for the slave to
commit
• Problematic in high DML load
What's New
• Multi threaded Slave
• Relay log recovery
• Binary Log Group Commit
• Crash-safe Replication – Binlog Checksums
• Global Transaction ID
You can read more in:
http://dev.mysql.com/tech-resources/articles/whats-new-in-mysql-5.6.html
Replication performance is improved by using
multiple execution threads to apply replication
events
slave-parallel-workers=2
You can read more in:
http://dev.mysql.com/tech-resources/articles/whats-new-in-mysql-5.6.html
• slave can automatically recover from a failure and
resume replicating DML updates
• the slave can roll back replication to the last
successfully committed transaction
relay-log-recovery =1
You can read more in:
http://dev.mysql.com/tech-resources/articles/whats-new-in-mysql-5.6.html
And in
Bug #13893363
• Commit a group of transactions to the binary log.
• Ensures durability with good performance.
• Designed to handle seamlessly temporary peeks
on the workload.
enable by default in 5.6
You can read more in:
http://dev.mysql.com/tech-resources/articles/whats-new-in-mysql-5.6.html
MySQL replication best practices 105-232-931
Master and slave can have different data
• Non deterministic queries.
• Wrong use of replication filters.
• Write executed on slave outside the.
replication (slave is not read only)
• Binlogs or relay log corruption.
How to check ?
Before 5.6 you can use only :
• show slave status
• pt-table-checksum
• utilty from precona that can check table
checksum
• First enable checksum on the master
binlog_checksum = CRC32;
master_verify_checksum = on;
• Then start binlog verify on the slave
slave_sql_verify_checksum = on;
* From >= 5.6.6 enable by default
mysql> show slave status
…
Last_Error : 1538
Last_Error : relay log read error……
…..
# mysqlbinlog --verify-binlog-checksum mysql_18676-relay-bin.000002
[...]
ERROR: Error in Log_event::read_log_event(): 'Event crc check failed!
Most likely there is event corruption.', data_len: 103, event_type: 2
ERROR: Could not read entry at offset 283: Error in log format or read
error.
[...]
Pros
• Can help to find error in the bin log/relay log
• Notify on a bin log corruption
Cons
• More CPU for the CRC
• The MySQL will keep writing to the corrupt bin log
MySQL replication best practices 105-232-931
• Transactions are not guaranteed to execute in
the order of the Binary logs
• The show slave status is not accurate
Master
Slave
1
Slave
2
Binlog
File:mysql-bin.0010
Position:1238574
Binlog
File:mysql-bin.0020
Position:1043
Binlog
File:mysql-bin.0140
Position:8373
• The same event can have different Binary log file
and position on different slaves
• Hard to find inconsistency in replication
• Very problematic to reconfigure replication
• Unique identifier of a transaction across all servers in
replication topology
The GTID look like :
GTID = source_id:transaction_id
Where
transaction_id = transaction_start-transaction_stop
eg :
3E11FA47-71CA-11E1-9E33-C80AA9429562:1-5
Master
Slave
1
Slave
2
Binlog
File:mysql-bin.0010
3E11FA47-71CA-11E1-9E33-C80AA9429562:1-5
Binlog
File:mysql-bin.0020
3E11FA47-71CA-11E1-9E33-C80AA9429562:1-5
Binlog
File:mysql-bin.0140
3E11FA47-71CA-11E1-9E33-C80AA9429562:1-5
How to enable GUID on MySQL replication
• Enable read only mode on Slaves
set global read_only=1
• Compare the binlog position on master and slave
show slave status
show master status
• Change configuration on all servers and restart
bin-log
guid_mode=ON
Enforce-guid-consistency
• Initialize GUID on all servers
change master to MASTER_AUTO_POSITION = 1;
• Disable read only mode on Slaves
MySQL replication best practices 105-232-931
Master
Blue
192.168.1.110
Slave
White
192.168.1.111
Master
Blue
192.168.1.110
Slave
White
192.168.1.111
Data files
from
Master
Blue
TRX1
TRX2
TRX3
.
Binary
log
Master
Blue
192.168.1.110
Slave
White
192.168.1.111
Replication
blue.my.cnf
[mysqld]
...
server-id=1
report-host=blue
binlog-format=MIXED
log-bin
log-slave-updates=true
gtid-mode=on
enforce-gtid-consistency=true
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync-master-info=1
binlog-checksum=CRC32
master-verify-checksum=1
white.my.cnf
[mysqld]
...
server-id=2
report-host=white
binlog-format=MIXED
log-slave-updates=true
log-bin
gtid-mode=on
enforce-gtid-consistency=true
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync-master-info=1
slave-parallel-workers=2
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
On Master:
[mysqld]
rpl_semi_sync_master_enabled=1
rpl_semi_sync_master_timeout=1000 # 1 second
On each Slave:
[mysqld]
rpl_semi_sync_slave_enabled=1
we need to create the replication user on master
mysql> GRANT REPLICATION SLAVE ON *.* TO
replication@192.168.1.111 IDENTIFIED BY 'reppwd';
FLUSH PRIVILEGES;
create Hot backup with * Oracle Enterprise Backup
#mysqlbackup --port=3306 --protocol=tcp --
user=root --password --backup-dir=/data/backup
backup-and-apply-log
* Also can use Percona XtraBackup
• copy the backup directory to the slave via scp or
other method
on the master:
#tar –cvfZ /data/backup.taz /data/backup
#scp /data/backup.taz 192.168.1.111:/data/
on the slave:
#tar –xvfZ /data/backup.taz
• Start the Slave
#service start mysql
• Start the replication process that will start the
io_Thread and the sql_Thread
mysql>CHANGE MASTER TO
MASTER_HOST='192.168.1.110',
MASTER_USER='replication',
MASTER_PASSWORD='reppwd',
MASTER_AUTO_POSITION=1;
START SLAVE;
show slave statusG
*************************** 1. row********
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.110
Master_User: replication
Master_Log_File: blue-bin.000002
Read_Master_Log_Pos: 936
Relay_Log_File: white-relay-bin.000003
Relay_Log_Pos: 1146
Relay_Master_Log_File: blue-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
show slave statusG
*************************** 1. row********
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Master_UUID: 2671c08b-7cf0-11e2-ac39-00163ebee7c2
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log;
waiting for the slave I/O thread to update it
Retrieved_Gtid_Set: 2671c08b-7cf0-11e2-ac39-00163ebee7c2:1-4
Executed_Gtid_Set: 2671c08b-7cf0-11e2-ac39-00163ebee7c2:1-4
MySQL replication best practices 105-232-931
baruch@dbaces.com

More Related Content

PDF
Best practices for MySQL High Availability
PDF
MariaDB Galera Cluster - Simple, Transparent, Highly Available
PDF
MySQL highav Availability
PDF
Using advanced options in MariaDB Connector/J
PDF
MySQL Sandbox 3
PPTX
Maria DB Galera Cluster for High Availability
PDF
The Complete MariaDB Server Tutorial - Percona Live 2015
PDF
9 DevOps Tips for Going in Production with Galera Cluster for MySQL - Slides
Best practices for MySQL High Availability
MariaDB Galera Cluster - Simple, Transparent, Highly Available
MySQL highav Availability
Using advanced options in MariaDB Connector/J
MySQL Sandbox 3
Maria DB Galera Cluster for High Availability
The Complete MariaDB Server Tutorial - Percona Live 2015
9 DevOps Tips for Going in Production with Galera Cluster for MySQL - Slides

What's hot (20)

PDF
High Availability with Galera Cluster - SkySQL Road Show 2013 in Berlin
PDF
Building better Node.js applications on MariaDB
PDF
Using and Benchmarking Galera in different architectures (PLUK 2012)
PPTX
Easy MySQL Replication Setup and Troubleshooting
PDF
Almost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
PDF
Ansible is Our Wishbone(Automate DBA Tasks With Ansible)
PDF
MySQL features missing in MariaDB Server
PDF
MySQL Parallel Replication: inventory, use-cases and limitations
PPTX
MariaDB Enterprise & MariaDB Enterprise Cluster - MariaDB Webinar July 2014
PPT
Galera cluster - SkySQL Paris Meetup 17.12.2013
PDF
Meet MariaDB 10.1 at the Bulgaria Web Summit
PDF
MySQL Parallel Replication (LOGICAL_CLOCK): all the 5.7 (and some of the 8.0)...
PDF
Best practices for MySQL/MariaDB Server/Percona Server High Availability
PDF
Meet MariaDB Server 10.1 London MySQL meetup December 2015
PDF
Choosing a MySQL High Availability solution - Percona Live UK 2011
ODP
MySQL HA with PaceMaker
PDF
MySQL/MariaDB Parallel Replication: inventory, use-case and limitations
PDF
Tuning Linux for your database FLOSSUK 2016
PDF
How Booking.com avoids and deals with replication lag
PDF
MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
High Availability with Galera Cluster - SkySQL Road Show 2013 in Berlin
Building better Node.js applications on MariaDB
Using and Benchmarking Galera in different architectures (PLUK 2012)
Easy MySQL Replication Setup and Troubleshooting
Almost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
Ansible is Our Wishbone(Automate DBA Tasks With Ansible)
MySQL features missing in MariaDB Server
MySQL Parallel Replication: inventory, use-cases and limitations
MariaDB Enterprise & MariaDB Enterprise Cluster - MariaDB Webinar July 2014
Galera cluster - SkySQL Paris Meetup 17.12.2013
Meet MariaDB 10.1 at the Bulgaria Web Summit
MySQL Parallel Replication (LOGICAL_CLOCK): all the 5.7 (and some of the 8.0)...
Best practices for MySQL/MariaDB Server/Percona Server High Availability
Meet MariaDB Server 10.1 London MySQL meetup December 2015
Choosing a MySQL High Availability solution - Percona Live UK 2011
MySQL HA with PaceMaker
MySQL/MariaDB Parallel Replication: inventory, use-case and limitations
Tuning Linux for your database FLOSSUK 2016
How Booking.com avoids and deals with replication lag
MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
Ad

Similar to MySQL replication best practices 105-232-931 (20)

PDF
MySQL 5.6 Replication Webinar
PDF
MySQL database replication
PDF
Best practices for MySQL High Availability Tutorial
ODP
MySQL 101 PHPTek 2017
PDF
2012 replication
PDF
MySQL Replication Basics -Ohio Linux Fest 2016
PPTX
Performance & Scalability Improvements in Perforce
PDF
MySQL Replication Update -- Zendcon 2016
PPT
Galera webinar migration to galera cluster from my sql async replication
PDF
2012 scale replication
PDF
OSDC 2018 | Scaling & High Availability MySQL learnings from the past decade+...
PPTX
Securing Hadoop @eBay
PDF
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
PDF
[db tech showcase Tokyo 2014] B15: Scalability with MariaDB and MaxScale by ...
PDF
What’s new in Galera 4
PPT
Mysql replication @ gnugroup
PDF
MySQL Parallel Replication: inventory, use-case and limitations
PDF
Slides: Introducing the new ClusterControl 1.2.9 - with live demo
PDF
Galera Cluster 4 presentation at Percona Live Austin 2019
PDF
Parallel Replication in MySQL and MariaDB
MySQL 5.6 Replication Webinar
MySQL database replication
Best practices for MySQL High Availability Tutorial
MySQL 101 PHPTek 2017
2012 replication
MySQL Replication Basics -Ohio Linux Fest 2016
Performance & Scalability Improvements in Perforce
MySQL Replication Update -- Zendcon 2016
Galera webinar migration to galera cluster from my sql async replication
2012 scale replication
OSDC 2018 | Scaling & High Availability MySQL learnings from the past decade+...
Securing Hadoop @eBay
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
[db tech showcase Tokyo 2014] B15: Scalability with MariaDB and MaxScale by ...
What’s new in Galera 4
Mysql replication @ gnugroup
MySQL Parallel Replication: inventory, use-case and limitations
Slides: Introducing the new ClusterControl 1.2.9 - with live demo
Galera Cluster 4 presentation at Percona Live Austin 2019
Parallel Replication in MySQL and MariaDB
Ad

MySQL replication best practices 105-232-931