Best Practices for Migrating MySQL to the Cloud
Juan Pablo Arruti Percona
Best Practices for Migrating MySQL to the Cloud Juan Pablo Arruti - - PowerPoint PPT Presentation
Best Practices for Migrating MySQL to the Cloud Juan Pablo Arruti Percona Agenda IaaS vs DBaaS Migrating Data Replication between On-Premises and Cloud Testing Cloud Environments High Availability Monitoring
Juan Pablo Arruti Percona
2
4
5
Database as a Service (DBaaS)
○ Setup, Operate, Scale
○ Backups, Patching, Failure Detection, Failover
○ RDS, DynamoDB, Redshift
6
7
8
1
1 1
1 2
1 3
○ Most adopted tool ○ Single-threaded
○ Introduced in MySQL 5.7 ○ Parallel backups ○ Restores are Single-threaded
○
Parallel backups and restores
1 4
Best Practices for MySQL Clients
○
○
○
○ DEFINER=`user`@`host`
○
1 5
Best Practices for MySQL Clients
○ RDS uses mysql schema Time Zone Tables ○ Recommended ■ Set session time_zone to match source database
1 6
Speeding Up Logical Restore
○ Relax Durability ■ sync_binlog != 1 ■ innodb_flush_log_at_trx_commit != 1 ○ Tune InnoDB ■ Increase innodb_log_file_size (Default 128 MB) ■ Increase innodb_buffer_pool_size (Default DBInstanceClassMemory*3/4)
1 7
1 8
2
2 1
Best Practices
○ Use compression for Master/Slave protocol ■ slave_compressed_protocol=1 ○ Monitor replication lag with pt-heartbeat
○ binlog_format = ROW
2 2
STATEMENT) ○ Recommended ROW to avoid time_zone mismatch
○ mysql.rds_set_external_master ○ mysql.rds_start_replication ...
2 4
2 5
2 6
SELECT c FROM sbtest37 WHERE id=505; --> thread 67 slower query was run in 86 microseconds instead of 34 Detailed Report
... Report
Spent 00:09:08.631886 executing queries versus an expected 00:04:43.697328 time. 23610 queries were quicker than expected, 2138262 were slower A total of 0 queries had errors. Expected 40606531 rows, got 40606533 (a difference of 2) Number of queries where number of rows differed: 2. Average of 113782.74 queries per connection (19 connections).
2 7
2 8
2 9
3
3 1
3 2
mysql> select * from stats_mysql_query_digest where digest_text like 'SELECT c FROM sbtest1 %' ORDER BY hostgroup \G *************************** 1. row *************************** hostgroup: 1 schemaname: sbtest username: jptest digest: 0x290B92FD743826DA digest_text: SELECT c FROM sbtest1 WHERE id BETWEEN ? AND ? count_star: 48864 first_seen: 1558761934 last_seen: 1558765725 sum_time: 14788745778 min_time: 2877 max_time: 3733095 *************************** 2. row *************************** hostgroup: 2 schemaname: sbtest username: jptest digest: 0x290B92FD743826DA digest_text: SELECT c FROM sbtest1 WHERE id BETWEEN ? AND ? count_star: 48832 first_seen: 1558761936 last_seen: 1558765725 sum_time: 16477562501 min_time: 2786 max_time: 4651554
3 4
Why are they useful?
○ Cloud Load Balancing ○ ProxySQL
3 5
○ RDS not supported ○ Routes traffic only across Availability Zones ○ Custom MySQL health checks can be used
3 6
3 7
3 8
3 9
4
4 1
4 3
4 4
4 5
4 6
4 7
4 8
4 9
5
5 2
5 3
shell> mysqldump --all-databases > mysql.dump.sql shell> gzip mysql.dump.sql shell> aws s3 cp mysql.dump.sql.gz s3://mysqlbucketprod/mysql.dump.sql.gz upload: ./mysql.dump.sql.gz to s3://mysqlbucketprod/mysql.dump.sql.gz
shell> mysqldump --all-databases | gzip | aws s3 cp - \ s3://mysqlbucketprod/mysql.dump.sql.gz
5 4
shell> xtrabackup --backup --stream=xbstream --extra-lsndir=/tmp \
xbcloud put --storage=s3 \
$(date +"%Y%m%d%H%M%S")-full_backup
5 5
58