AWS

4 Mins Read

Detailed Guide to Access Database hosted on EC2 Remotely

Voiced by Amazon Polly

Overview of Hosted and Traditional Database

Traditional databases provide for the management of underlying business resources and infrastructure on corporate premises. Fortunately, cloud databases have transformed that industry by making the same resources available on a pay-as-you-go basis.

Provisioning firm infrastructure and resources in data centers to administer and on-site a database is costly and time-consuming. Traditional databases need extensive preparation in terms of purchase orders for both hardware and database software.

Cloud databases have a crucial advantage over traditional databases in that they allow organizations with critical data-resource requirements to grow on demand without worrying about availability or security—the cloud provides multiple database replication across several geographical locations.

Customized Cloud Solutions to Drive your Business Success

  • Cloud Migration
  • Devops
  • AIML & IoT
Know More

Real-time Scenario Example

Let us suppose that you want to use a database in your application, but you don’t have any data center to host your database, so you have chosen the cloud to host the database. Instead of a managed database, you have opted for a custom installation of a database in the server

Here, I have used the AWS EC2 server to host the database. The database engine is MySQL 8.0.29

Prerequisites

AWS Account

  1. EC2 Instance
  2. User with privileges to create an instance

Steps to install MySQL in AWS EC2

Step 1 – Launch an EC2 Server with Ubuntu 18.04

Step1

Step 2 – Check the security group of EC2 Server, which has MySQL/Aurora Port open only from specified IP Address and SSH port from your IP Address

Step2

Step 3 – SSH inside the machine

Step3

Step 4 – SSH Inside the machine and Update and install mysql-server

Step 5 – Go inside your MySQL

Step 6 – Alter root user credentials for the database and flush all the privileges

Step 7 – Check whether the password is applied for the root user or not

Steps to Connect to EC2 database remotely

Step 1 – Create a new remote user in MySQL, create a new user, and give permission as required. Here I’m giving all privileges to test

Step01

Note: Don’t use any reserved keyword to create a remote user like (root, Admin, Admin)

Step 2 – Change the data-bind address to the IP where you want to access the database

  • Set the MySQL server to listen to all IP addresses on the system if you wish to connect to it via a public network. To do so, modify the MySQL configuration file and add or update the bind-address option’s value. You can configure a single IP address as well as IP ranges. The MySQL server accepts connections on all host IPv4 interfaces if the address is 0.0.0.0. If your machine is set for IPv6, use: instead of 0.0.0.0
  • Depending on the distribution, the location of the MySQL configuration file varies. The file is placed at /etc/mysql/mysql.conf.d/mysqld.cnf in Ubuntu and Debian, and at/etc/my.cnf in Red Hat-based distributions such as CentOS.

Step02

Step 3 – Restart MySQL Server

Step03

Step 4 – Check Connection

Check connection of database using PHP

Step04a

Step04b

Conclusion

If you need an automated solution, go for the managed database; for more control and flexibility, go for manual database hosting.

For some cases like automated backups, security, and updating versions, this will be taken care of by managed database. If you want to have control of the OS, manage your database by looking after clustering and replication, then go for the manually hosted database.

The choice ultimately comes down to whether you prefer manual or automated operations, how much time it will cost, and your management abilities.

Get your new hires billable within 1-60 days. Experience our Capability Development Framework today.

  • Cloud Training
  • Customized Training
  • Experiential Learning
Read More

About CloudThat

CloudThat is a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.

CloudThat is the first Indian Company to win the prestigious Microsoft Partner 2024 Award and is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 850k+ professionals in 600+ cloud certifications and completed 500+ consulting projects globally, CloudThat is an official AWS Advanced Consulting Partner, Microsoft Gold Partner, AWS Training PartnerAWS Migration PartnerAWS Data and Analytics PartnerAWS DevOps Competency PartnerAWS GenAI Competency PartnerAmazon QuickSight Service Delivery PartnerAmazon EKS Service Delivery Partner AWS Microsoft Workload PartnersAmazon EC2 Service Delivery PartnerAmazon ECS Service Delivery PartnerAWS Glue Service Delivery PartnerAmazon Redshift Service Delivery PartnerAWS Control Tower Service Delivery PartnerAWS WAF Service Delivery PartnerAmazon CloudFront Service Delivery PartnerAmazon OpenSearch Service Delivery PartnerAWS DMS Service Delivery PartnerAWS Systems Manager Service Delivery PartnerAmazon RDS Service Delivery PartnerAWS CloudFormation Service Delivery PartnerAWS ConfigAmazon EMR and many more.

FAQs

1. Should the subnet associated with the server be public or private?

ANS: – The subnet should be public. Otherwise, we would not be able to connect the database to the application code

2. Can we access the hosted database on private IP?

ANS: – Yes, if our hosted database and Application code lie in the same VPC

3. Are manual hosted databases best as compared to the database which Cloud Providers offer?

ANS: – If you want to have complete control over the database users and privileges including patching and updating, then you can opt for hosting the database manually otherwise hosted DB which is offered by cloud providers are good option to pick up

4. Can we secure the manually hosted database?

ANS: – Yes, you can secure the manual hosted database from three different places- (i) From AWS Network Access Control List (NACL)
(ii)From EC2 Security Group
(iii)From MySQL config file bind-address
(iv)By giving required access to users created in the database

WRITTEN BY Rishi Raj

Share

Comments

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!