16.4 Connect from EC2
SSH into the EC2 instance in the same VPC. Install only the client. Do not install a second database server.
# Amazon Linux 2023 — the mariadb105 package provides the mysql command
sudo yum install -y mariadb105
# Ubuntu
sudo apt update && sudo apt install -y mysql-client
# CentOS Stream 9 — mariadb is the client. Do not install mariadb-server
sudo yum install -y mariadb
mysql -h appdb.abc123xyz.ap-south-1.rds.amazonaws.com -P 3306 -u admin -p appdb
Replace the hostname with your endpoint. -p with nothing after it makes the client ask for the password, so the password is not saved in the shell history. You should get a mysql> prompt.
CREATE TABLE students (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(40) NOT NULL,
marks INT
);
INSERT INTO students (name, marks) VALUES ('Asha', 88), ('Rahul', 76);
SELECT * FROM students;
EXIT leaves the client. If this query works, the security group, the endpoint and the password are all correct.