Advanced MySQL replication techniques Giuseppe Maxia.

Slides:



Advertisements
Similar presentations
PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect.
Advertisements

Drop in replacement of MySQL. Agenda MySQL branch GPL licence Maria storage engine Virtual columns FederatedX storage engine PBXT storage engine XtraDB.
Senior Solutions Architect, MongoDB Inc. Massimo Brignoli Introduction to Replication and Replica Sets.
Get Your Replication On: Advanced Techniques, Tips and Tricks Chris Schneider Sarah Sproehnle.
By César Urdaneta.  Purpose ◦ Replicate records from different tables (for inserting / updating record), from a source database to a target one, keeping.
How do I setup SQL log Shipping and why should I care Steve
Introduction to MySQL Administration.  Server startup and shutdown ◦ How to manually start and stop it from the command line ◦ How to arrange an automated.
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
CS 603 Data Replication in Oracle February 27, 2002.
Reliable MySQL Using Replication Issac Goldstand Mirimar Networks
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
Chapter 7 Constraints and Triggers Spring 2011 Instructor: Hassan Khosravi.
Chapter 18: Modifying SAS Data Sets and Tracking Changes 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Replication with MySQL 5.1 Ligaya Turmelle Senior Technical Support Engineer - MySQL
MySql In Action Step by step method to create your own database.
Databases with PHP A quick introduction. Y’all know SQL and Databases  You put data in  You get data out  You can do processing on it very easily 
1. When things go wrong: how to find SQL error Sveta Smirnova Principle Technical Support Engineer, Oracle.
CHAPTER 21 Automating Jobs. Introduction to Automating Jobs DBAs rely heavily on automating jobs. DBAs cannot be effective without automation. Listed.
INTERNET APPLICATION DEVELOPMENT For More visit:
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Maintaining a Mirrored Database Tips and Tricks by Paul G. Hiles.
Dbwebsites 2.1 Making Database backed Websites Session 2 The SQL… Where do we put the data?
© Continuent 2010 Liberating Your Data From MySQL: Cross-Database Replication to the Rescue! Robert Hodges and Linas Virbalas Continuent, Inc.
Understanding How MySQL Works by Understanding Metadata Sheeri Cabral and Patrick Galbraith.
The MySQL General Purpose Routine library Giuseppe Maxia.
ITN Wake Tech1 ITN270 Advanced Internet Databases Lecture 15. General MySQL Administration Topics: –Securing a New MySQL Installation –MySQL Server.
Introduction to MySQL Lab no. 10 Advance Database Management System.
Copyright 2006 MySQL AB The World’s Most Popular Open Source Database MySQL Cluster: An introduction Geert Vanderkelen MySQL AB.
CpSc 462/662: Database Management Systems (DBMS) (TEXNH Approach) Constraints, Triggers and Index James Wang.
Triggers A Quick Reference and Summary BIT 275. Triggers SQL code permits you to access only one table for an INSERT, UPDATE, or DELETE statement. The.
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
A Brief Documentation.  Provides basic information about connection, server, and client.
1 ISYS Triggers. 2 Agenda Triggers Review Correlation identifiers (pseudo records) Restrictions on triggers Trigger usage Mutating tables Enabling.
MySQL More… 1. More on SQL In MySQL, the Information Schema is the “Catalog” in the SQL standard SQL has three components: Data definition Data manipulation.
What’s a database? Data stored in a structured format that lends itself to easy manipulation and recall.
Get Rid of Cron Scripts Using Events Sheeri Cabral Senior DB Admin/Architect,
Using Flash with php Very quick introduction to Flash Homework: work on projects.
Different Constraint Types Type Where Declared When activated Guaranteed to hold? Attribute with attribute on insertion not if CHECK or update subquery.
Database server Campus-Booster ID : ****** Copyright © SUPINFO. All rights reserved MySQL.
Alwayson Availability Groups
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 5 SQL.
INLS 623– T RIGGERS Instructor: Jason Carter. F INAL E XAM Classes end on Dec. 2 nd Exam Days start on December 4 th Final Exam is on December 10 at 4pm.
There are two types of MySQL instructions (Data Definition Language) DDL: Create database, create table, alter table,,,. (Data Manipulation Language) DML.
Perfecto Mobile Automation
Ch 7. Working with relational data. Transactions Group of statements executed as a group. If all statements execute successfully, changes are committed.
1 Chapter Overview Using Standby Servers Using Failover Clustering.
Replicazione e QoS nella gestione di database grid-oriented Barbara Martelli INFN - CNAF.
Log Shipping, Mirroring, Replication and Clustering Which should I use? That depends on a few questions we must ask the user. We will go over these questions.
Narasimha Reddy Gopu Jisha J. Agenda Introduction to AlwaysOn * AlwaysOn Availability Groups (AG) & Listener * AlwaysOn Failover * AlwaysOn Active Secondaries.
Introduction to MySQL  Working with MySQL and MySQL Workbench.
AlwaysOn In SQL Server 2012 Fadi Abdulwahab – SharePoint Administrator - 4/2013
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
1 Backup and Replication Integration Techniques MySQL 6.0 Lars Thalmann, PhD Mats Kindahl, PhD Chuck Bell, PhD Replication and Backup Team Sun Microsystems.
AlwaysOn Mirroring, Clustering
Instructor: Jason Carter
Learning MongoDB ZhangGang
A Technical Overview of Microsoft® SQL Server™ 2005 High Availability Beta 2 Matthew Stephen IT Pro Evangelist (SQL Server)
Error Handling Summary of the next few pages: Error Handling Cursors.
Deep Dive: Replication
Overview Implementing Triggers Implementing XML Schemas.
CS122B: Projects in Databases and Web Applications Spring 2017
CS122B: Projects in Databases and Web Applications Winter 2017
Unit I-2.
CS122B: Projects in Databases and Web Applications Winter 2018
AlwaysOn Availability Groups
CS122B: Projects in Databases and Web Applications Spring 2018
Chapter 11 Managing Databases with SQL Server 2000
CS122B: Projects in Databases and Web Applications Winter 2019
Ch 10. Maintaining and Automating SQL Server
Presentation transcript:

Advanced MySQL replication techniques Giuseppe Maxia

About me

Agenda Replication basics Circular replication Automatic failover Failover with circular replication

Replication goals Data redundancy Load balancing Backup points Base for failover

Replication basics One single point of data insertion and changes (MASTER) more points of data read (SLAVES) Different IDs for each server Binary log Replication slave user Replication threads (IO and SQL)

Replication basics binary log relay log run (SQL) read (I/O) read (I/O)

Circular Replication More points of data insertion and changes (MASTER) Each slave is also a master Insertion conflicts!

Circular Replication

# CONFLICT CREATE TABLE x ( id int(11) NOT NULL AUTO_INCREMENT, c char(10) DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=MyISAM

Circular Replication # CONFLICT #(assume broken connection between nodes) [node A] insert into x (c) values ('aaa'), ('bbb'), ('ccc'); [node B] insert into x (c) values ('xxx'), ('yyy'), ('zzz');

Circular Replication # CONFLICT #(when connection is resumed) Error 'Duplicate entry '1' for key 'PRIMARY'' on query. Default database: 'test'. Query: 'insert into x (c) values ('aaa')'

Circular Replication [node A] select * from x; | id | c | | 1 | aaa | | 2 | bbb | | 3 | ccc | [node B] select * from x; | id | c | | 1 | xxx | | 2 | yyy | | 3 | zzz |

Circular Replication solving auto-increment conflicts

Circular Replication # SOLVING AUTO-INCREMENT CONFLICTS # in both nodes STOP SLAVE; RESET MASTER; RESET SLAVE; TRUNCATE x;

Circular Replication # SOLVING AUTO-INCREMENT CONFLICTS [NodeA] set auto_increment_increment = 10; set auto_increment_offset = 1; [NodeB] set auto_increment_increment = 10; set auto_increment_offset = 2;

Circular Replication # SOLVING AUTO-INCREMENT CONFLICTS # (Slaves still stopped) [node A] insert into x (c) values ('aaa'), ('bbb'), ('ccc'); [node B] insert into x (c) values ('xxx'), ('yyy'), ('zzz');

Circular Replication [node A] select * from x; | id | c | | 1 | aaa | | 11 | bbb | | 21 | ccc | [node B] select * from x; | id | c | | 2 | xxx | | 12 | yyy | | 22 | zzz |

Circular Replication # SOLVING AUTO-INCREMENT CONFLICTS # (resume replicastion) [node A] SLAVE START; [node B] SLAVE START;

Circular Replication # SOLVING AUTO-INCREMENT CONFLICTS # (resume replication) [node A] SHOW SLAVE STATUS\G [node B] SHOW SLAVE STATUS\G... Slave_IO_Running: Yes Slave_SQL_Running: Yes...

More Circular Replication

Failover basics Master replacement inform each slave about the new master

Failover scenario (1)

Failover scenario (2a)

Failover scenario (2b) # in the master CREATE TABLE who ( server_id int ) ENGINE=MyIsam

Failover scenario (2c) # in each slave CREATE TABLE master_who ( server_id int ) ENGINE=Federated 06/replica/who';

Failover scenario (2d) # in each slave (requires MySQL 5.1) create event check_master_conn on schedule every 30 second enable do call check_master();

Failover scenario (2e) create procedure check_master() begin declare master_dead boolean default false; declare curx cursor for select server_id from replica.master_who; declare continue handler for SQLSTATE 'HY000' set master_dead = true;...

Failover scenario (2f) procedure check_master()... open curx; # a failure to open the cursor # occurs here # setting the master_dead variable # to true

Failover scenario (2g) procedure check_master()... if (master_dead) then stop slave; change master to master_host=' ', master_log_file='binlog_name', master_log_pos=0; start slave; alter event check_master_conn disable; end if;

Failover scenario (3)

Failover scenario (4)

Circular Failover (1)

Circular Failover (2)

Circular Failover (3)

Try it ! The Replication playground

Failover example (1) # replication playground $./start_all.sh $./check_slaves.sh Slave_IO_Running: Yes Slave_SQL_Running: Yes Slave_IO_Running: Yes Slave_SQL_Running: Yes Slave_IO_Running: Yes Slave_SQL_Running: Yes

Failover example (2) # replication playground $./use.sh my.nodeC.cnf replica nodeC> show slave status \G... Master_Host: Master_User: nodeCuser Master_Port:

Failover example (3) # replication playground nodeC> select * from check_master_log; | ts | master_status | | :39:26 | master OK | | :39:56 | master OK |

Failover example (4) # replication playground $./stop_all.sh A nodeA shutdown

Failover example (5) # replication playground nodeC> select * from check_master_log; | ts | master_status | | :39:26 | master OK | | :39:56 | master OK | | :40:26 | master is dead |

Failover example (6) # replication playground $./use.sh my.nodeC.cnf replica nodeC> show slave status \G... Master_Host: Master_User: nodeCuser Master_Port:

THANKS Any questions?