Amazon RDS for MySQL: Best Practices and Migration

Post on 15-Jul-2015

601 views 2 download

Transcript of Amazon RDS for MySQL: Best Practices and Migration

© 2011 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Amazon RDS for MySQL: Best

Practices and Data Migration

Amazon RDS

Amazon RDS

Amazon RDS is simple and fast to deploy

Amazon RDS handles management tasks

DB

Master

App

Backup

AWS Region

Replication

App

scp Load data

Staging server

DB Slave

SQL Flat files

mysql> GRANT SELECT,REPLICATION USER,REPLICATION CLIENT ON *.* TO repluser@‘<RDS Endpoint>' IDENTIFIED BY ‘<password>';

Create replication user on the master

Record the “File” and the “Position” in the backup

$ mysqldump --databases sampledb --master-data=2 --single-transaction -r sampledbdump.sql -u mysqluser –p mysqluserpassword

---- Position to start replication or point-in-time recovery from--

-- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin-changelog.000031', MASTER_LOG_POS=107;

Configure replication target

mysql> call mysql.rds_set_external_master(‘<master server>',3306,‘<replicationuser>',‘<password>','mysql-bin-changelog.000031',107,0);

mysql> call mysql.rds_start_replication;

Configure the replication target and start replication

Stop the app pointing at the source. Stop replication after target catches up

mysql> call mysql.rds_stop_replication;

Promote target Amazon RDS database instance

mysql> call mysql.rds_reset_external_master;

Point the app at the target Amazon RDS database instance

AWS Region

App

Dump Data

Staging server

scp & load

MasterSlave

mysql> call mysql.rds_set_configuration('binlog retention hours', 48);

Physical

synchronous

replication

AZ1 AZ2

DNS

cname update

Sync

replication

Async replication

[ERROR] Slave I/O: Got fatal error 1236 from master when reading data from binary log: ‘Client requested master to start replication from impossible position;

Source: https://blogs.oracle.com/MySQL/entry/mysql_5_6_replication_performance

AZ1 AZ2 AZ1

Reads10% Reads10% Reads10% Reads10%Reads10% Reads10% Reads10% Reads10%

Reads10%Writes10%

Reads10%Reads10%Writes10%

Reads10%Reads10%Writes10%

Reads10%Reads10%Writes10%

Reads10%

Reads10%Writes10%

Reads10%Reads10%Writes10%

Reads10%Reads10%Writes10%

Reads10%Reads10%Writes10%

Reads10%

Reads10%Writes10%Reads10%Writes10%Reads10%

Reads

90%

Writes10%

Primary

Writes10%

Replica1

Writes10%

Replica2

Writes10%

Replica3

Writes10%

Replica4

1X2X3X SCALE

Writes 20% Writes 20% Writes 20% Writes 20%

Reads

80%

Reads 20% Reads 20% Reads 20% Reads 20%

Reads 20%

Writes 20%

Reads 20%

Writes 20%

Reads 20%

Writes 20%

Reads 20%

Writes 20%

Writes 20%

Writes20%

Primary Replica1 Replica2 Replica3 Replica4

1X2X SCALE

Series1

Series2

Series3

Series4

Series5

1

2

3

4

5

6

7

8

1 2 3 4 5 6

Scale

Scale based on % Write

4x

Load buffer pool

Dump buffer pool

0

5000

10000

15000

20000

25000

30000

1 3 5 7 9

11

13

15

17

19

21

23

25

27

29

31

33

35

37

39

41

43

45

47

49

51

53

55

57

59

61

63

65

67

69

Tra

nsa

cti

on

s p

er

Se

co

nd

Time (sec)

Workload with 50/50 R/W ratio

Unwarmed Cache

Warmed Cache4X

9 min

mysql> CREATE EVENT ‘evt_dump_innodb_cache’

ON SCHEDULE EVERY 1 HOUR STARTS ‘2014-11-06 01:00:00’

DO BEGIN CALL mysql.rds_innodb_buffer_pool_dump_now();

END

Considerations Options

Read Only

ReplicaPrimary R2MasterR/W

mysql> ALTER TABLE customers_address ADD COLUMN province VARCHAR(100);

pt-online-schema-change --alter "ADD COLUMN province VARCHAR(100)" --execute h=localhost,D=bench,t=customers_address,u=admin,p=admin

Logging + Storage

SQL

Transactions

Caching

Control PlaneData Plane

Amazon S3

DynamoDB

Amazon SWF

Amazon Route 53

© 2011 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Questions?