Amazon RDS for MySQL: Best Practices and Migration

40
© 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

Transcript of Amazon RDS for MySQL: Best Practices and Migration

Page 1: 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

Page 2: Amazon RDS for MySQL: Best Practices and Migration
Page 3: Amazon RDS for MySQL: Best Practices and Migration

Amazon RDS

Amazon RDS

Page 4: Amazon RDS for MySQL: Best Practices and Migration

Amazon RDS is simple and fast to deploy

Page 5: Amazon RDS for MySQL: Best Practices and Migration

Amazon RDS handles management tasks

Page 6: Amazon RDS for MySQL: Best Practices and Migration
Page 7: Amazon RDS for MySQL: Best Practices and Migration
Page 8: Amazon RDS for MySQL: Best Practices and Migration
Page 9: Amazon RDS for MySQL: Best Practices and Migration

DB

Master

App

Backup

AWS Region

Replication

App

scp Load data

Staging server

DB Slave

Page 10: Amazon RDS for MySQL: Best Practices and Migration
Page 11: Amazon RDS for MySQL: Best Practices and Migration
Page 12: Amazon RDS for MySQL: Best Practices and Migration

SQL Flat files

Page 13: Amazon RDS for MySQL: Best Practices and Migration

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;

Page 14: Amazon RDS for MySQL: Best Practices and Migration

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

Page 15: Amazon RDS for MySQL: Best Practices and Migration

AWS Region

App

Dump Data

Staging server

scp & load

MasterSlave

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

Page 16: Amazon RDS for MySQL: Best Practices and Migration
Page 17: Amazon RDS for MySQL: Best Practices and Migration

Physical

synchronous

replication

AZ1 AZ2

DNS

cname update

Page 18: Amazon RDS for MySQL: Best Practices and Migration

Sync

replication

Async replication

Page 19: Amazon RDS for MySQL: Best Practices and Migration

[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;

Page 20: Amazon RDS for MySQL: Best Practices and Migration

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

Page 21: Amazon RDS for MySQL: Best Practices and Migration

AZ1 AZ2 AZ1

Page 22: Amazon RDS for MySQL: Best Practices and Migration
Page 23: Amazon RDS for MySQL: Best Practices and Migration

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

Page 24: Amazon RDS for MySQL: Best Practices and Migration

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

Page 25: Amazon RDS for MySQL: Best Practices and Migration

Series1

Series2

Series3

Series4

Series5

1

2

3

4

5

6

7

8

1 2 3 4 5 6

Scale

Scale based on % Write

Page 26: Amazon RDS for MySQL: Best Practices and Migration

4x

Load buffer pool

Dump buffer pool

Page 27: Amazon RDS for MySQL: Best Practices and Migration

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

Page 28: Amazon RDS for MySQL: Best Practices and Migration
Page 29: Amazon RDS for MySQL: Best Practices and Migration

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

Page 30: Amazon RDS for MySQL: Best Practices and Migration

Considerations Options

Page 31: Amazon RDS for MySQL: Best Practices and Migration

Read Only

ReplicaPrimary R2MasterR/W

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

Page 32: Amazon RDS for MySQL: Best Practices and Migration
Page 33: Amazon RDS for MySQL: Best Practices and Migration

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

Page 34: Amazon RDS for MySQL: Best Practices and Migration
Page 35: Amazon RDS for MySQL: Best Practices and Migration
Page 36: Amazon RDS for MySQL: Best Practices and Migration
Page 37: Amazon RDS for MySQL: Best Practices and Migration

Logging + Storage

SQL

Transactions

Caching

Control PlaneData Plane

Amazon S3

DynamoDB

Amazon SWF

Amazon Route 53

Page 38: Amazon RDS for MySQL: Best Practices and Migration
Page 39: Amazon RDS for MySQL: Best Practices and Migration
Page 40: 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.

Questions?