Amazon RDS Aurora replication to external serverAmazon RDS Aurora (MySQL) provides its own low latency replication. Nevertheless, there are cases where it can be beneficial to set up replication from Aurora to an external MySQL server, as Amazon RDS Aurora is based on MySQL and supports native MySQL replication. Here are some examples of when replicating from Amazon RDS Aurora to an external MySQL server can make good sense:

  • Replicating to another cloud or datacenter (for added redundancy)
  • Need to use an independent reporting slave
  • Need to have an additional physical backup
  • Need to use another MySQL flavor or fork
  • Need to failover to another cloud and back

In this blog post I will share simple step by step instructions on how to do it.

Steps to setup MySQL replication from AWS RDS Aurora to MySQL server

  1. Enable binary logs in the option group in Aurora (Binlog format = mixed). This will require a restart.
  2. Create a snapshot and restore it (create a new instance from a snapshot). This is only needed to make a consistent copy with mysqldump. As Aurora does not allow “super” privileges, running mysqldump --master-data  is not possible. The snapshot is the only way to get a consistent backup with the specific binary log position.
  3. Get the binary log information from the snapshot. In the console, look for the “Alarms and Recent Events” for the restored snapshot instance. We should see something like:
  4. Install MySQL 5.6 (i.e. Percona Server 5.6) on a separate EC2 instance (for Aurora 5.6 – note that you should use MySQL 5.7 for Aurora 5.7). After MySQL is up and running, import the timezones:

    Sample config:
  5. From now on we will make all backups from the restored snapshot. First get all users and import those to the new instance:

    # check that grants are valid and upload to MySQL

    Make a backup of all schemas except for the “mysql” system tables as Aurora using different format of those (make sure we connect to the snapshot):
  6. Restore to the local database:
  7. Restore users again (some users may fail to create where there are missing databases):
  8. Download the RDS/Aurora SSL certificate:
  9. Configure MySQL replication. Take the values for the binary log name and position from #3 above. Please note: now we connect to the actual instance, not a snapshot:
  10. Verify that the slave is working. Optionally add the SQL_Delay option to the CHANGE MASTER TO (or anytime) and specify the slave delay in seconds.

I hope those steps will be helpful for setting up an external MySQL replica.

You May Also Like

Grow Your Business with an AWS RDS MySQL Environment. This solution brief outlines setting up MySQL Amazon RDS instances to meet your company’s growing needs.

Download: The AWS RDS MySQL Environment Solution Brief

5 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Khurram Naseem

mysqldump with terabytes of data, how we can optimise it ?

Chris Schneider

@khurram you may want to try mydumper (https://github.com/maxbube/mydumper)

perydell

Is Amazon supporting external replicas for all RDS instances or is this just an Aurora thing?

Ian

Out of interest do you have a guide to do the reverse of this? On prem MySQL to Aurora?

Ramki

aws supports restoring xtrabackup backups for mysql 5.6 compatible Aurora, it doesn’t support mysql 5.7 yet.