Step-by-Step Guide- Connecting Amazon RDS to EC2 Using MySQL Driver

Creating the Database

  1. Navigate to Amazon RDS

    Navigate to Amazon RDS by clicking on "Services" in the top left corner of the AWS Management Console. Under the Database category, click on "RDS".

  2. Click on "Create database"

  3. Select standard template and MariaDb as a Database Engine.

  4. Choose database version and Select "Dev/Test" or "Production" based on your use case.

  5. Now, give a name to your database and set a username. The default username is "admin," but you can change it. Choose the self-managed credential manager to set your own custom password, or you can auto-generate the password.

  6. Leave the rest of the settings below as they are.

  7. Click on "Create database."

  8. Wait for the database to be created.


Creating the EC2 Instance

Follow this article to create an EC2 instance in simple steps.


Install MySQL Client on EC2 Instance

Run the command below to update packages on your machine.

sudo apt update

Now, run this command to install the MySQL Client.

sudo apt install mysql-client

Now, go to the RDS database you created and click on Security Group.

After clicking, you will be taken to this page.

Click on this security group and go to Inbound Rules. We need to access the RDS database from our EC2 instance, and the database is running on port 3306. To allow traffic from our EC2 instance to the database server, edit the inbound rules and add the following rules.

Now run the command below to connect the EC2 instance to the RDS database. Use the username and password you set during the database creation, and the Database Endpoint URL you can find in the RDS Connectivity & security section.

mysql -h <endpointUrl> -u <username> -p<pasword>

For Example :


Conclusion

Congratulations! You have successfully created an Amazon RDS database instance with the MariaDB engine and connected it to an EC2 instance using the MySQL driver. Amazon RDS makes database management easier by handling routine tasks like backups, patches, and scaling, so you can focus on building your applications. With your EC2 instance connected to Amazon RDS, you can now develop and deploy applications that use the power and scalability of cloud-based databases.


Feel free to ask any questions or share your experience with Amazon RDS and EC2 in the comments below. Happy cloud computing!

0
Subscribe to my newsletter

Read articles from GUNJAN NIMBALKAR directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

GUNJAN NIMBALKAR
GUNJAN NIMBALKAR