Mysql – Is it possible to Clone an Existing MYSQL Slave Database into Amazon RDS with the RDS clone being a slave to an external Master

amazon-rdsMySQLreplication

We are interested in migrating our data from one of our MYSQL slave databases to an Amazon RDS instance such that the new RDS database is a slave database to an external master DB from our colocation/facility.

I was reading through the documentation for RDS and was not keen on bringing our master mysql server down/stop writes while the import into RDS is taking place. I would prefer doing that import processing on an existing slave database.

We use some of the existing Percona tools to create slaves from existing slaves but I'm sure there are limitations on RDS so any helpful advise is appreciated.

Master MYSQL Version: 5.6.11-log MySQL Community Server (GPL)
Slave MYSQL Version: 5.6.11-log MySQL Community Server (GPL)

Best Answer

This is completely possible. The only type of import you can use with RDS is a logical restore, so mysqldump. You will want to use the --dump-slave=2 option :

mysqldump --dump-slave=2 (other options) > dump.sql

This will add the CHANGE MASTER statement as a SQL comment to the dump.sql file. Take the binary log file and log position from that statement and set the RDS up accordingly:

CALL mysql.rds_set_external_master (
  host_name
  , host_port
  , replication_user_name
  , replication_user_password
  , <binary log file>
  , <binary log position>
);

[src]

I would caution you that your replication events are going to be sent as plain text, since ssl_encryption is not implemented for RDS MySQL. If your existing master is not in AWS, to be secure you would need to have your RDS instance in a VPC and set up to communicate with a VPN in your existing infrastructure. Read more about this in the docs: https://aws.amazon.com/vpc/