β Day 18 of My Cloud Journey β MySQL on EC2: Setup + SQL Queries π―

Table of contents
- π What is MySQL?
- π‘ Why MySQL Matters
- βοΈ Install MySQL on Amazon EC2 (Amazon Linux 2)
- π» Accessing the MySQL Shell
- ποΈ DATABASE + TABLE CREATION
- βοΈ INSERT β Add Data
- π SELECT β Read Data
- π οΈ UPDATE β Modify Records
- β DELETE β Remove Records
- π Relational Data + JOIN
- π₯ Create a New MySQL User
- π Allowing Remote Access (Optional & Risky)
- π Final Thoughts
- π Whatβs Next?
Today I rolled up my sleeves and dove into MySQL, a powerful relational database used by millions of applications. In this blog, Iβll show you:
What MySQL is & why itβs essential
How to install MySQL on EC2
How to configure MySQL securely
CRUD operations (Create, Read, Update, Delete)
Database relationships with
JOIN
Real SQL queries for hands-on practice
π What is MySQL?
MySQL is an open-source relational database used to manage structured data in rows and columns. It supports SQL (Structured Query Language) and is often used with PHP, Python, and web apps like WordPress, Laravel, Django, etc.
π‘ Why MySQL Matters
Feature | Description |
πΎ Stores structured data | Rows, columns, tables |
π§ Supports relationships | Foreign keys, JOINs |
π‘οΈ Secure | User privileges, authentication |
β‘ Fast & Scalable | Powers large-scale apps |
π» Open-source | Free to use and widely adopted |
βοΈ Install MySQL on Amazon EC2 (Amazon Linux 2)
π§© Prerequisites
Amazon EC2 instance (Amazon Linux 2)
Port 22 open for SSH
Optional: Port 3306 open (for remote access)
π¦ Step-by-Step Installation
# Step 1: Update system packages
sudo yum update -y
# Step 2: Install MySQL server
sudo yum install mysql-server -y
# Step 3: Start the MySQL service
sudo systemctl start mysqld
# Step 4: Enable MySQL to start on boot
sudo systemctl enable mysqld
π Secure the MySQL Installation
sudo mysql_secure_installation
β
Set root password
β
Remove anonymous users
β
Disallow root remote login
β
Remove test database
β
Reload privileges
π» Accessing the MySQL Shell
mysql -u root -p
Enter the password you set above to access the MySQL command-line interface.
ποΈ DATABASE + TABLE CREATION
π Create a new database
CREATE DATABASE school;
USE school;
π Create a table
CREATE TABLE students (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100),
grade INT
);
βοΈ INSERT β Add Data
INSERT INTO students (name, email, grade)
VALUES
('Alice Johnson', 'alice@example.com', 85),
('Bob Smith', 'bob@example.com', 90),
('Charlie Brown', 'charlie@example.com', 78);
π SELECT β Read Data
-- Show all records
SELECT * FROM students;
-- Filtered records
SELECT name, grade FROM students WHERE grade > 80;
-- Count students
SELECT COUNT(*) FROM students;
π οΈ UPDATE β Modify Records
-- Update a single student's grade
UPDATE students
SET grade = 95
WHERE name = 'Alice Johnson';
β DELETE β Remove Records
DELETE FROM students WHERE grade < 80;
π Relational Data + JOIN
Letβs create a related table and use a JOIN.
CREATE TABLE courses (
course_id INT AUTO_INCREMENT PRIMARY KEY,
course_name VARCHAR(100)
);
CREATE TABLE enrollments (
enrollment_id INT AUTO_INCREMENT PRIMARY KEY,
student_id INT,
course_id INT,
FOREIGN KEY (student_id) REFERENCES students(id),
FOREIGN KEY (course_id) REFERENCES courses(course_id)
);
Add Course Data
INSERT INTO courses (course_name) VALUES ('Math'), ('Science');
Add Enrollment Data
INSERT INTO enrollments (student_id, course_id)
VALUES (1, 1), (2, 2);
JOIN Students + Courses
SELECT s.name, c.course_name
FROM students s
JOIN enrollments e ON s.id = e.student_id
JOIN courses c ON e.course_id = c.course_id;
π₯ Create a New MySQL User
CREATE USER 'clouduser'@'%' IDENTIFIED BY 'StrongPass123';
GRANT ALL PRIVILEGES ON school.* TO 'clouduser'@'%';
FLUSH PRIVILEGES;
π Allowing Remote Access (Optional & Risky)
Edit config:
sudo nano /etc/my.cnf
Replace:
bind-address = 127.0.0.1
With:
bind-address = 0.0.0.0
Restart MySQL:
sudo systemctl restart mysqld
Allow port 3306 in Security Group if needed.
π Final Thoughts
Todayβs experience gave me hands-on exposure to:
β
Setting up a relational DB
β
Writing SQL for real data
β
Understanding how MySQL connects to backend apps
β
Practicing database relationships and queries
These are fundamental skills for hosting WordPress, building full-stack apps, and backend development in general!
π Whatβs Next?
Day 19: Iβll explore advanced SQL queries, practice JOINs and constraints, and prepare for deploying WordPress with a real MySQL backend.
π Topics:
Normalization
Foreign Keys
Backup & Restore
Connecting MySQL to WordPress (LAMP/LEMP)
Subscribe to my newsletter
Read articles from Pratik Das directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
