Saturday, February 9, 2013 - Khan Kennels › presentations › pdf ›...
Transcript of Saturday, February 9, 2013 - Khan Kennels › presentations › pdf ›...
1
Saturday, February 9, 2013
<Insert Picture Here>
Replication With MySQLLigaya Turmelle Principle Technical Support Engineer - MySQL https://joind.in/8017
Saturday, February 9, 2013
3
<Insert Picture Here>
[email protected] Support Engineer
MySQL ACE~8 years
@lig
About Me
Saturday, February 9, 2013
4
TODO List
• Foundation• Overview• Asynchronous and Semi-Synchronous• Setup• Monitoring
Saturday, February 9, 2013
5
Foundation
Saturday, February 9, 2013
6
Baby Steps
Network
Saturday, February 9, 2013
7
Why would you want to do that?
Saturday, February 9, 2013
• Scale Out
8
Why would you want to do that?
Saturday, February 9, 2013
• Scale Out• Data Redundancy
9
Why would you want to do that?
Saturday, February 9, 2013
• Scale Out• Data Redundancy• Analytics
10
Why would you want to do that?
Saturday, February 9, 2013
• Scale Out• Data Redundancy• Analytics• Long distance data distribution
11
Why would you want to do that?
Saturday, February 9, 2013
<Insert Picture Here>
12
MySQL Terminology
Saturday, February 9, 2013
• Method of Sending the Data
13
Terminology
Saturday, February 9, 2013
• Method of Sending the Data• Asynchronous Replication - since 3.23
14
Terminology
Saturday, February 9, 2013
• Method of Sending the Data• Asynchronous Replication - since 3.23• Semi-Synchronous Replication - 5.5+
15
Terminology
Saturday, February 9, 2013
• Where to Store the Changes
16
Terminology
Saturday, February 9, 2013
• Where to Store the Changes• Binary Log - Master
17
Terminology
Saturday, February 9, 2013
• Where to Store the Changes• Binary Log - Master• Relay Log - Slave
18
Terminology
Saturday, February 9, 2013
• Method of Replication
19
Terminology
Saturday, February 9, 2013
• Method of Replication• SBR - Statement Based Replication
20
Terminology
Saturday, February 9, 2013
• Method of Replication• SBR - Statement Based Replication• RBR - Row Based Replication
21
Terminology
Saturday, February 9, 2013
• Method of Replication• SBR - Statement Based Replication• RBR - Row Based Replication• Mixed Mode
• http://dev.mysql.com/doc/refman/5.5/en/binary-log-mixed.html
22
Terminology
Saturday, February 9, 2013
• Replication Threads
23
Terminology
Saturday, February 9, 2013
• Replication Threads • Slave Server
• IO Thread
24
Terminology
Saturday, February 9, 2013
• Replication Threads • Slave Server
• IO Thread• SQL Thread
25
Terminology
Saturday, February 9, 2013
• Replication Threads • Master Server
• Binlog Dump Thread
26
Terminology
Saturday, February 9, 2013
27
Overviews
Saturday, February 9, 2013
<Insert Picture Here>
28
MySQL Replication
Saturday, February 9, 2013
29
Highlevel Replication Overview
1Master
Saturday, February 9, 2013
30
Highlevel Replication Overview
Binarylog
1
2
Master
Saturday, February 9, 2013
31
Highlevel Replication Overview
RelayLog
Binarylog
1
3
2
Master
Saturday, February 9, 2013
32
Highlevel Replication Overview
Slave
RelayLog
Binarylog
1
4
3
2
Master
Saturday, February 9, 2013
33
Asynchronous vsSemi-Synchronous
Saturday, February 9, 2013
<Insert Picture Here>
34
Asynchronous Replication
Saturday, February 9, 2013
35
Asynchronous
Master Slave
Saturday, February 9, 2013
36
Asynchronous
Master SlaveIO Thread (3)
Binlog DumpThread created
Saturday, February 9, 2013
37
Asynchronous
Master Slave
Binarylog
IO Thread (3)
Binlog DumpProcess
Saturday, February 9, 2013
38
Asynchronous
Master Slave
RelayLog
Binarylog
IO Thread (3)
Binlog DumpProcess
IO Thread (3)
Saturday, February 9, 2013
• Pros• Fast• slave can be disconnected
• Cons• Potential loss of transactions and data integrity
39
Asynchronous
Saturday, February 9, 2013
<Insert Picture Here>
40
Semi-Synchronous Replication
Saturday, February 9, 2013
41
Semi-Synchronous
Master Slave
semi-synccapable
semi-synccapable
Saturday, February 9, 2013
42
Semi-Synchronous
Master SlaveIO Thread (3)
Binlog DumpThread created
semi-sync capablesemi-synccapable
semi-synccapable
Saturday, February 9, 2013
43
Semi-Synchronous(optimal)
Saturday, February 9, 2013
44
Semi-Synchronous(optimal)
Master SlaveIO Thread
Binlog DumpThreadCreated
semi-synccapable
semi-synccapable
1
Saturday, February 9, 2013
45
Semi-Synchronous(optimal)
Master Slave
RelayLog
Binarylog
IO Thread
Binlog DumpProcess
IO Thread (save)
semi-synccapable
semi-synccapable
1
x
Saturday, February 9, 2013
46
Semi-Synchronous(optimal)
Master SlaveIO Thread semi-synccapable
semi-synccapable
1
RelayLog
Binarylog
Binlog DumpProcess
IO Thread (ack)
Saturday, February 9, 2013
47
Semi-Synchronous(timeout)
Saturday, February 9, 2013
48
Semi-Synchronous(timeout)
Master SlaveIO Thread
Binlog DumpThreadCreated
semi-synccapable
semi-synccapable
1
Saturday, February 9, 2013
49
Semi-Synchronous(timeout)
Master Slave
Binarylog
IO Thread
Binlog DumpProcess
semi-synccapable IO Thread (save)
semi-synccapable
1
xNetwork
Saturday, February 9, 2013
50
Semi-Synchronous(timeout)
Master Slave
Binarylog
IO Thread
Binlog DumpProcess
semi-synccapable IO Thread (save)
semi-synccapable
1
xNetwork
TIMEOUT
Saturday, February 9, 2013
51
Semi-Synchronous(timeout)
Master Slave
Binarylog
IO Thread
Binlog DumpProcess
async semi-synccapable
1
Saturday, February 9, 2013
52
Semi-Synchronous(timeout)
Master Slave
RelayLog
Binarylog
IO Thread
Binlog DumpProcess
IO Thread (save)
async semi-synccapable
Saturday, February 9, 2013
53
Semi-Synchronous(timeout)
Master Slave
RelayLog
Binarylog
IO Thread
Binlog DumpProcess
IO Thread (save)
async semi-synccapable
resync
Saturday, February 9, 2013
54
Semi-Synchronous(timeout)
Master Slave
RelayLog
Binarylog
IO Thread (synced)
Binlog DumpProcess
async semi-synccapable
resync
Saturday, February 9, 2013
55
Semi-Synchronous(timeout)
Master Slave
RelayLog
Binarylog
Binlog DumpProcess
semi-synccapable
IO Thread semi-synccapable
Saturday, February 9, 2013
• Pros• Tries to improve data integrity
• Cons• Performance Implications
56
Semi-Synchronous
Saturday, February 9, 2013
57
Setting it Up
Saturday, February 9, 2013
<Insert Picture Here>
58
Asynchronous -Master
Saturday, February 9, 2013
• Config/Option file• my.cnf/my.ini
59
Asynchronous - Master
log-bin=mysql_binserver_id=1
Saturday, February 9, 2013
60
Asynchronous - Mastermysql> CREATE USER 'repl'@'%.mydomain.com' IDENTIFIED BY 'slavepass';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%.mydomain.com';
• Create replication user• requires
REPLICATION SLAVE privilege
Saturday, February 9, 2013
61
Asynchronous - Mastermysql> FLUSH TABLES WITH READ LOCK;
mysql> SHOW MASTER STATUS; • Master server binary log coordinates• requires
REPLICATION SLAVE privilege
Saturday, February 9, 2013
• While the tables are locked• if you need a copy of the master, this is the time to make it
• Once you have a copy, release the locks
62
Asynchronous - Master
mysql> UNLOCK TABLES;
Saturday, February 9, 2013
<Insert Picture Here>
63
Asynchronous -Slave
Saturday, February 9, 2013
• Config/Option file• my.cnf/my.ini
64
Asynchronous - Slave
server_id=2read-only
Saturday, February 9, 2013
• Load in the copy/backup from the master• always verify that the backup works
65
Asynchronous - Slave
Saturday, February 9, 2013
66
Asynchronous - Slavemysql> CHANGE MASTER TO
MASTER_HOST = 'master.mycompany.com', MASTER_USER = 'repl', MASTER_PASSWORD='slavepass', MASTER_PORT=3306, MASTER_LOG_FILE='master-bin. 001', MASTER_LOG_POS=4;
mysql> START SLAVE;
• Issue CHANGE MASTER command• info from MASTER
STATUS
Saturday, February 9, 2013
<Insert Picture Here>
67
Semi-Synchronous -Master
Saturday, February 9, 2013
68
Semi-Synchronous - Mastermysql> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
mysql> SHOW PLUGINS;• Install PLUGIN
• Server must support dynamic loading (see have_dynamic_loading)
Saturday, February 9, 2013
69
Semi-Synchronous - Mastermysql> SET GLOBAL rpl_semi_sync_master_enabled = 1;
mysql> SET GLOBAL rpl_semi_sync_master_timeout = N;
• Enable PLUGIN• default is off
Saturday, February 9, 2013
• Config/Option file• my.cnf/my.ini
70
Semi-Synchronous - Master
log-bin=mysql_binserver_id=1
# semi-sync replrpl_semi_sync_master_enabled = 1rpl_semi_sync_master_timeout = 1000 # 1 sec
Saturday, February 9, 2013
<Insert Picture Here>
71
Semi-Synchronous -Slave
Saturday, February 9, 2013
72
Semi-Synchronous - Slavemysql> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
mysql> SHOW PLUGINS;• Install PLUGIN
• Server must support dynamic loading (see have_dynamic_loading)
Saturday, February 9, 2013
73
Semi-Synchronous - Slavemysql> SET GLOBAL rpl_semi_sync_slave_enabled = 1;
• Enable PLUGIN• Default is Off
Saturday, February 9, 2013
74
Semi-Synchronous - Slavemysql> STOP SLAVE IO_THREAD;
mysql> START SLAVE IO THREAD;• Runtime
Saturday, February 9, 2013
• Config/Option file• my.cnf/my.ini
75
Semi-Synchronous - Slave
server_id=2read-only
# semi-sync replrpl_semi_sync_slave_enabled=1
Saturday, February 9, 2013
76
Monitoring
Saturday, February 9, 2013
<Insert Picture Here>
77
Monitoring -Master
Saturday, February 9, 2013
• Gives file name and position• Lists filtering done on Master
78
Master Status
mysql> SHOW MASTER STATUS;+---------------+----------+--------------+------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |+---------------+----------+--------------+------------------+| mysql-bin.003 | 73 | test | manual,mysql |+---------------+----------+--------------+------------------+
Saturday, February 9, 2013
• Gives the binary logs on the server
79
Binary Logs
mysql> SHOW BINARY LOGS;+---------------+-----------+| Log_name | File_size |+---------------+-----------+| binlog.000015 | 724935 || binlog.000016 | 733481 |+---------------+-----------+
Saturday, February 9, 2013
<Insert Picture Here>
80
Monitoring -Slave
Saturday, February 9, 2013
81
Slave Statusmysql> SHOW SLAVE STATUS\G*************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: localhost Master_User: root Master_Port: 3306 Connect_Retry: 3 Master_Log_File: mysql-bin.003 Read_Master_Log_Pos: 73 Relay_Log_File: mysql-relay-bin.005 Relay_Log_Pos: 548 Relay_Master_Log_File: mysql-bin.003 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table:
Saturday, February 9, 2013
82
Slave Status Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 73 Relay_Log_Space: 552 Until_Condition: None Until_Log_File: Last_SQL_Error: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 8Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error:
Saturday, February 9, 2013
• State Slave_IO_State: Waiting for master to send event
• Running Slave_IO_Running: Yes
Slave_SQL_Running: Yes
• Last Error Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error:
83
Slave Status - Basic Stuff
Saturday, February 9, 2013
• Where everything is• IO Thread
Master_Log_File: mysql-bin.003 Read_Master_Log_Pos: 73
84
Slave Status - Important Stuff
Saturday, February 9, 2013
• Where everything is• SQL Thread
• Relay Log Relay_Log_File: mysql-relay-bin.005 Relay_Log_Pos: 548
• Binary Log Relay_Master_Log_File: mysql-bin.003 .... Exec_Master_Log_Pos: 73
85
Slave Status - Important Stuff
Saturday, February 9, 2013
• Show Caution
Seconds_Behind_Master: 8
86
Slave Status - Caution
Saturday, February 9, 2013
• Lot of changes• Global Transaction ID• Binary Log Group Commit• Parallel execution of transactions on the slave• Crash-safe Replication• And more
87
MySQL 5.6
Saturday, February 9, 2013
88
Questions?
Saturday, February 9, 2013
89
Saturday, February 9, 2013