Skip to main content

Command Palette

Search for a command to run...

AWS RDS MySQL Database Setup and EC2 Connection Guide

Updated
โ€ข4 min read
AWS RDS MySQL Database Setup and EC2 Connection Guide

๐Ÿš€ AWS RDS MySQL Database Creation and Connection Using EC2

In this hands-on project, I created an Amazon RDS MySQL database, launched an EC2 instance, installed the MySQL client, and connected the EC2 instance to the RDS database securely. This is a fundamental AWS project for anyone learning Cloud, DevOps, or Database Administration.


๐Ÿ“Œ Architecture

EC2 Instance (Ubuntu)
        |
        |
        v
Amazon RDS (MySQL)

The EC2 instance acts as the client machine, while Amazon RDS hosts the MySQL database.


Step 1: Create an Amazon RDS MySQL Database

  1. Log in to the AWS Management Console.

  2. Search for RDS and open the service.

  3. Click Create Database.

  4. Select:

    • Standard Create

    • MySQL

    • Free Tier (for practice)

  5. Enter:

    • DB Instance Identifier: database-1

    • Master Username: admin

    • Master Password: ********

  6. Under Connectivity:

    • Choose a VPC

    • Enable Public Access (for testing)

    • Create a new Security Group or use an existing one

  7. Click Create Database.

Wait until the database status changes to Available.


Step 2: Configure RDS Security Group

To allow EC2 to communicate with the database:

  1. Open the RDS instance.

  2. Navigate to Connectivity & Security.

  3. Click the attached Security Group.

  4. Edit Inbound Rules.

  5. Add:

Type Port Source
MySQL/Aurora 3306 EC2 Security Group

Save the rule.


Step 3: Launch an EC2 Instance

  1. Open EC2 Dashboard.

  2. Click Launch Instance.

  3. Configure:

    • Name: mysql-client

    • AMI: Ubuntu Server

    • Instance Type: t2.micro

  4. Create or select a key pair.

  5. Configure Security Group:

    • SSH (22)
  6. Launch Instance.


Step 4: Connect to EC2

Using EC2 Instance Connect or SSH:

ssh -i key.pem ubuntu@<public-ip>

Update packages:

sudo apt update

Step 5: Install MySQL Client

Install the MySQL client package:

sudo apt install mysql-client -y

Verify installation:

mysql --version

Expected output:

mysql  Ver 8.x

Step 6: Copy the RDS Endpoint

  1. Open RDS Console.

  2. Select your database.

  3. Under Connectivity & Security, copy the Endpoint.

Example:

database-1.xxxxxx.us-east-2.rds.amazonaws.com

Step 7: Connect EC2 to RDS

Run:

mysql -h database-1.xxxxxx.us-east-2.rds.amazonaws.com -u admin -p

Enter the RDS password when prompted.

Successful connection:

Welcome to the MySQL monitor.
mysql>

Step 8: Create a Database

Inside MySQL:

CREATE DATABASE box;

Verify:

SHOW DATABASES;

Output:

+--------------------+
| Database           |
+--------------------+
| box                |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

Step 9: Use the Database

USE box;

Create a table:

CREATE TABLE students (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
course VARCHAR(50)
);

Verify:

SHOW TABLES;

Step 10: Insert Sample Data

INSERT INTO students(name,course)
VALUES ('Suguna','AWS DevOps');

Check data:

SELECT * FROM students;

Output:

+----+--------+------------+
| id | name   | course     |
+----+--------+------------+
| 1  | Suguna | AWS DevOps |
+----+--------+------------+

๐ŸŽฏ Key Learnings

โœ… Created an Amazon RDS MySQL database

โœ… Configured Security Groups

โœ… Launched an EC2 Instance

โœ… Installed MySQL Client

โœ… Connected EC2 to RDS

โœ… Created a Database and Tables

โœ… Inserted and Retrieved Data


Conclusion

Amazon RDS simplifies database management by handling backups, patching, and high availability. By connecting an EC2 instance to an RDS MySQL database, we can securely manage and interact with cloud-hosted databases without maintaining database servers ourselves.

This project demonstrates a real-world AWS architecture commonly used in production environments for web applications and enterprise systems.

๐Ÿ”– Hashtags for LinkedIn/Hashnode

#AWS #AmazonRDS #MySQL #EC2 #CloudComputing
#AWSCloud #DevOps #DatabaseAdministration
#Linux #AWSProjects #CloudLearning
#AWSTutorial #Hashnode #DevOpsEngineer

Suggested Header Title

"AWS RDS MySQL Setup: Creating a Database and Connecting Through EC2"