Creating an AWS RDS Replica for MySql

Amazon RDS is an easy to set up AWS-managed database service. Amazon RDS supports two types of replication features: 1) Multi-AZ Deployments 2) Read Replicas.

In Multi-AZ deployment, RDS stores a standby database replica in another availability zone. Here database updates are simultaneously applied to the main node and the replica node. If a failover occurs, RDS will automatically shift the operations to the standby replica node without inheriting any interruptions in database operations.

In the case of a Read replica, there is also a standby replica but this replica cannot be accessed directly prior to any failover. This behavior can be used for elastic scaling of a DB instance. For read-heavy database workloads, one can create several replicas of a source database instance within the same AWS region or in a different AWS region.

Starting from Jan 11, 2018 Amazon RDS read replicas for MySQL and its fork MariaDB databases now come with a facility of deployment in multi availability zones. 

The primary or master database updates are asynchronously transferred to the read replicas. Besides providing scalability, read replicas can also be used for disaster recovery. For e.g. if the primary DB instance fails, the replica can be prompted as a standalone instance and work on the behalf of the primary database. 

What will we cover?

In this guide, we will see how to create a read replica of a MySql RDS database instance.

Key Notes Regarding Read Replica

Before we proceed further, consider some of the key notes regarding Read Replicas:

  1. It is a best practice to configure a read replica in the same way a master DB instance is configured.
  2. The only supported database engines for read replicas include: MariaDB, Microsoft SQL Server, MySQL, Oracle, and PostgreSQL.
  3. The default storage type of a read replica is the same as that of the source DB instance. The storage type can also be changed while creating the read replica.
  4. Please note that while changing the storage size allocated to a read replica, you cannot increase it by a value less than 10 percent.
  5. Circular replication is not supported by Amazon RDS.
  6. Replicas of different DB engines have several differences.
  7. A short I/O suspension occurs while creating a read replica.
  8. For creating a read replica, automatic backups should be set to enabled on the source DB instance. This can be done by setting the backup retention period value greater than ‘0’.

Creating Read Replicas from AWS Management Console

Before we proceed with the read replica, get your DB instance started and running. Now head to the RDS management console, here we can see our DB instance ‘database-1’ which is based on MySQL DB is running:

Primary DB instance

Note: To create a read replica we can use AWS console, AWS CLI and RDS API. 

Our primary database configuration is as follows:

DB instance identifier: ‘database-1’
Database engine: MySql
Database version: 8.0.28
Master username: ‘Your-username’
Master password: ‘Your-password’
DB instance class: db.t2.micro (Free-tier)
Storage size: 20 GiB 
Public Access: ‘No’
Automated backups: ‘Enabled’


With the above DB configuration we will now continue with the read replica:

Step 1. From the RDS management console, select the target DB instance. Now click on the ‘Action’ drop down menu located above and choose the option ‘Create read replica’: 

Creating Read Replica for database-1

Step 2. On the next page, some settings are already pre-selected based on the best practice approach. Here we are sticking to the best practice, but we are free to change them.

Step 3. Under the ‘Replica source’, choose the source DB instance for the read replica. Enter a name for the Read Replica DB instance (‘DBreplica’ in our case). Also choose a region for launching the read replica. We have selected the same region for the read replica as that of the DB instance. 

Replica db settings

We are sticking to the preselected settings for DB instance class and storage details.

DB instance configuration

The storage auto-scaling option is already enabled under the Storage section.

Step 4. Under Multi-AZ deployment you can create fallback support or standby for the replica by selecting ‘yes’. For now we are skipping this option:

Multi-AZ deployment configuration option

Step 5. Our read replica is not publicly accessible as we have chosen the ‘Not publicly accessible’ option. Also the database authentication is based on ‘Password authentication’.

Accessibility and authentication configurationtion

Step 6. Since we have not enabled the encryption option for the source DB instance, we have also skipped it here. In the same way the monitoring, logging option and deletion protection are left untouched.

Step 7. Inside the Additional configuration option of the database, the port value can be changed to other than the default value. To copy the tags to snapshots, check the ‘Copy tags to snapshots’ checkbox. The IAM DB authentication can be enabled for managing the database via an IAM user. One more optional thing you can do is to enable minor database updates.

 Remaining Settings

Step 8. Now click the ‘Create read replica’ button to start the replica creation process.

Read Replica being created

If you prefer to use the AWS CLI way, you can create the read replica by using the ‘create-db-instance-read-replica’ command with the required cli options:

$ aws rds create-db-instance-read-replica --db-instance-identifier DBreplica --source-db-instance-identifier database-1 --max-allocated-storage 1000

Wrapping Up

In this guide, we have seen how to create a read replica for a MySql database. Read replicas provides you with an asynchronously copied read-only version of the primary database, thereby providing you scalability as well as a standby recovery database.

Share this page:

0 Comment(s)