mysql replication basics

17
MySQL Replication 19 April 2014 Abdul Manaf

Upload: abdul-manaf

Post on 21-Feb-2017

76 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: MySQL Replication Basics

MySQL Replication

19 April 2014Abdul Manaf

Page 2: MySQL Replication Basics

Agenda

• Basics of Replication

• Why Replication needed

• Types Of Replication

• Replication For MySQL

• Configuring MySQL Replication

• Test a Replicated MySQL System

Page 3: MySQL Replication Basics

Basics of Replication

• Master / Slave, Master / Master and Circular replication

• Master writes all DDL and DML statements in the binary log

• Slaves read the binary log from the master and run the queries locally

• A master can have many slaves

• A slave can have only one master

• A server can be both a master and a slave

• MySQL Replication is asynchronous

Page 4: MySQL Replication Basics

Master - Slave and Master-Master Replication Architecture

Master – Slave

Master – Master

Page 5: MySQL Replication Basics

Circular Replication Architecture

Page 6: MySQL Replication Basics

Why Replication needed

• Using Replication for Backups : Data is replicated to the slave, and the slave can pause the replication process, it is possible to run backup services on the slave without touching the corresponding master data.

• Using Replication with Different Master and Slave Storage Engines for performance

• Using Replication for Scale-Out i.e Splitting load between servers Distributing READ and WRITE.

• Creating reporting system on slave

Page 7: MySQL Replication Basics

Types Of Replication

• Synchronous Replication

• Asynchronous Replication

Page 8: MySQL Replication Basics

Synchronous Replication

• Master Server waits for the data to have been recorded on the duplicated systems.

• Write either completes on both sides or not at all

• Uses the two-phase commit technology to protect data integrity

• Synchronous replication is essential for failover of transactional applications. With synchronous replication, all committed data on the disk of the first server are on the disk of the second server.

• Not in MySQL

Page 9: MySQL Replication Basics

Asynchronous Replication

• Write is considered complete as soon as local storage acknowledges.

• Performance is greatly increased. No need for two-phase commit protocol.

• In case of losing a local storage, the remote storage is not guaranteed to have the current copy of data.

• Slaves need not be connected permanently to receive updates from the master

Page 10: MySQL Replication Basics

Considerations before setting replication

• MySQL version of servers should be same.

• Master and slave should be able to commuincate with each other, create a test user on master and try to connect from slave.

Page 11: MySQL Replication Basics

How to set MySQL replication

• Configure replication account on the master i.e create a mysql replication user.

• Enable binary log and set server-id on the master my.cnf file

• Restart mysql master server

• Take backup from master server

• Configure slave for replication

• Restore backup on slave server

• Start replication using CHANGE MASTER and START SLAVE

Page 12: MySQL Replication Basics

Configure my.cnf

• Enable binary logging on the master

• Setup a server-id for the master

• Ensure that the skip-networking option has not been enabled, so that slave can communicate with it

Page 13: MySQL Replication Basics

Configure my.cnf

Page 14: MySQL Replication Basics

Configure my.cnf

Page 15: MySQL Replication Basics

Configure slave server

• Setup a server-id on slave as we have done on master, it should be different from master.

• Other variables like for configuring slave MASTER_HOST , MASTER_USER , MASTER_PASSWORD etc. We will be setting them by executing CHNAGE master

CHANGE MASTER TOMASTER_HOST = '192.168.9.236'MASTER_USER = 'repl'MASTER_PASSWORD = 'repl@123'MASTER_LOG_FILE = 'mysql-bin.000004'MASTER_LOG_POS = 108;

Page 16: MySQL Replication Basics

Known issues and their resolutions

• MySQL replication can fail silently, that is data can drift out of sync with the master without your knowing, You need to regularly monitor your replication setups.

• Use checksum tools from Percona to verify & compare tables on master & slave servers.

• Use rigorous monitoring to watch error logs, and checksum logs hourly if necessary.

• Use Percona sync tools to resync tables if they get out of sync.

• Be especially vigilant if you’re taking backups off the slave server

Page 17: MySQL Replication Basics

THANK YOU ALL