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
Log in to the AWS Management Console.
Search for RDS and open the service.
Click Create Database.
Select:
Standard Create
MySQL
Free Tier (for practice)
Enter:
DB Instance Identifier:
database-1Master Username:
adminMaster Password:
********
Under Connectivity:
Choose a VPC
Enable Public Access (for testing)
Create a new Security Group or use an existing one
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:
Open the RDS instance.
Navigate to Connectivity & Security.
Click the attached Security Group.
Edit Inbound Rules.
Add:
| Type | Port | Source |
|---|---|---|
| MySQL/Aurora | 3306 | EC2 Security Group |
Save the rule.
Step 3: Launch an EC2 Instance
Open EC2 Dashboard.
Click Launch Instance.
Configure:
Name:
mysql-clientAMI: Ubuntu Server
Instance Type: t2.micro
Create or select a key pair.
Configure Security Group:
- SSH (22)
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
Open RDS Console.
Select your database.
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"




