-
Client-Server
refers to an architecture in which two or more computers are connected together over a network to send and receive requests between one another. -
In their communication, each machine has its own role:
The machine sending requests is usually referred to as the "Client"
The machine responding (serving) is called the "Server"
Our Web Server has a role of a
Client
that connects and reads/writes to/from a Database (DB) Server (MySQL, MongoDB, Oracle, SQL Server or any other), and the communication between them happens over a Local Network (it can also be Internet connection, but it is a common practice to place Web Server and DB Server close to each other in local network).
๐ฏStep-by-step guide on how to implement MySQL Client-Server architecture on AWS EC2 Linux instances
1. ๐ผ Setup EC2 Instances
-
Create two EC2 instances running Ubuntu Linux.
-
Name one
mysql-server
and the othermysql-client
.

๐ Allow inbound traffic on port 3306 in mysql-server security group
-
Go to AWS Console > EC2 > Security Groups.
-
Select the security group attached to mysql-server.
-
Add a new Inbound rule: Select Custom TCP > Port 3306 > Enter the private IP of
MySQL-Client
instance only

2. ๐ ๏ธ On mysql-server instance: Install MySQL Server
- SSH into the Server instance.
ssh -i <Your-private-key.pem> ubuntu@<EC2-Public-IP-address>
- Update and Upgrade system packages:
sudo apt update && sudo apt upgrade
- install
MySQL Server
sudo apt install mysql-server -y

- Check MySQL service status
sudo systemctl status mysql

3. ๐๏ธ On mysql-client instance: Install MySQL Client
- SSH into the Client instance.
ssh -i <Your-private-key.pem> ubuntu@<EC2-Public-IP-address>
- Update and Upgrade system packages:
sudo apt update && sudo apt upgrade
- install
MySQL Server
sudo apt install mysql-client -y

4. ๐จ Configure MySQL server to accept remote connections
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

- Restart MySQL Server to apply changes
sudo systemctl restart mysql
5. ๐ Create MySQL user with remote access permissions on mysql-server
- Login to MySQL Server
sudo mysql
- Create a user that can connect remotely
CREATE USER 'remoteuser'@'client_private_ip' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON *.* TO 'remoteuser'@'client_private_ip' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

- Check that you have successfully connected to a remote MySQL server and can perform SQL queries:
show databases;

CREATE DATABASE binary_db;
USE binary_db;
INSERT INTO employees (name, position, salary) VALUES
('Oladapo', 'DevOps Engineer', 200000.00),
('Dolapo', 'IT Manager', 350000.00),
('Funmilayo', 'Intern', 75000.00);

- We have successfully implemented a basic Client-Server architecture using MySQL. By setting up two Linux-based EC2 instances, configuring MySQL for remote access, securing user permissions, and connecting via the MySQL client, weโve built a fully functional environment for remote database operations.