Introduction
In our previous guide, we learned how to create a MySQL database in AWS RDS. Now, let’s take it a step further and explore the process of creating a read replica for our “linuxchamp-masterdb” database.
Prerequisites
Before starting, ensure you have followed our previous guide on creating a MySQL database in AWS RDS. You can find the step-by-step guide here.
Step 1: Sign in to the AWS Console
- Log in to your AWS Management Console using your credentials.
Step 2: Navigate to RDS
- Once logged in, navigate to the RDS service by clicking “Services” in the top menu and selecting “RDS” under the Database section.
Step 3: Select RDS Instance
- Locate your “linuxchamp-masterdb” RDS instance in the dashboard.
Step 3: Enable Automated Backups (optional)
- Go to the “Backup” tab and check if automated backups are enabled. If backups are disabled (Figure 2), follow the next steps.
- Click on the “Actions” button for your RDS instance.
- Select “Turn on backups” from the dropdown menu (Figure 3).
- In the confirmation window, choose “Apply immediately” (Figure 4).
- Wait for the process to complete and verify again in the “Maintenance and Backups” tab if backups are now enabled (Figure 5).
Step 4: Create a Read Replica
- Navigate to the RDS service and find your “linuxchamp-masterdb” RDS instance.
- Click on the “Actions” button for your RDS instance.
- From the dropdown menu, select “Create Read Replica.”
- In the Create Read Replica wizard, configure the replica settings:
- Choose a unique identifier for the read replica, such as “linuxchamp-replica-1.”
- Select the appropriate instance class for the replica based on your requirements.
- Choose the desired storage type for the replica (e.g., General Purpose SSD, Provisioned IOPS SSD).
- Specify VPC settings if necessary, ensuring connectivity and security requirements are met.
- Review the configuration settings to ensure they align with your intended setup.
- Click on “Create Read Replica” to initiate the process.
Step 5: Monitor Replica Creation
- AWS will start creating the read replica. Monitor the progress in the RDS dashboard.
- Wait for the status to change to “Available,” indicating that the read replica is ready for use.
Step 6: Create a Parameter Group for the Replica
- In the left-hand menu, select “Parameter groups” under the “Database” section.
- Locate the parameter group associated with your master database (“linuxchamp-masterdb”), such as “pg-mysql8-v34.”
- Click on the “Actions” button next to the master database parameter group.
- From the dropdown menu, select “Copy.”
- In the “Copy parameter group” window:
- Provide a new DB parameter group identifier for the replica, such as “pg-mysql8-v34-replica-1.”
- Add a description for the new parameter group, such as “PG for linuxchamp replica 1.”
- Click on “Create” to create the replica parameter group based on the settings of the master database parameter group.
Step 7: Associate Parameter Group with Read Replica
- Select your read replica instance (“linuxchamp-replica-1”) from the list of databases.
- In the “Modify DB Instance” wizard, go to the “Database options” section.
- Choose the newly created parameter group for the read replica (“pg-mysql8-v34-replica-1”) from the dropdown menu.
- Click on “Modify Replica” and select “Apply immediately” to apply the changes without waiting for the next maintenance window.
- Go to the “Configuration” tab of your read replica instance.
- Wait for the parameter group update to show as “Pending Reboot.”
- Once the update status changes to “Pending Reboot,” proceed to the next step.
- Click on the “Instance actions” button for your read replica.
- After the replica reboots, return to the “Configuration” tab of your read replica instance.
- Verify that the new parameter group (“pg-mysql8-v34-replica-1”) is the current parameter group and is in sync with the replica.
Step 8: Verify Replication Before Moving Production Read Traffic
- Connect to your master database (“linuxchamp-masterdb”) using the following command:
mysql -h linuxchamp-masterdb.c508yy6y4o5o.us-east-1.rds.amazonaws.com -P 3306 -ulinuxchamp -p
- Once connected, create a database named “linuxchampdb” and switch to it:
CREATE DATABASE linuxchampdb;
USE linuxchampdb;
- Create a table named “users” with columns for “id”, “name”, and “email”:
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
email VARCHAR(50) NOT NULL
);
- Insert two sample records into the “users” table:
INSERT INTO users (name, email) VALUES
('John Doe', '[email protected]'),
('Jane Smith', '[email protected]');
- Connect to your read replica instance (“linuxchamp-replica-1”) using the following command:
mysql -h linuxchamp-replica-1.c508yy6y4o5o.us-east-1.rds.amazonaws.com -P 3306 -ulinuxchamp -p
- Once connected to the read replica, check if the “linuxchampdb” database exists:
SHOW DATABASES;
- If “linuxchampdb” exists, switch to the database:
USE linuxchampdb;
- Query the “users” table to check if the data is replicated accurately:
SELECT * FROM users;
- Compare the data retrieved from the read replica with those in the master database to ensure replication integrity.
Step 9: Conclusion
Congratulations! You have successfully created a read replica in AWS RDS, configured the master database, inserted data, and verified replication in the read replica. Leveraging read replicas enhances database performance and ensures data redundancy for your applications.