RDS (Relational Database System)
RDS stands for Relational database service, it is a fully managed service provided by AWS to create and host your database in an AWS cloud environment. Once your database is created on AWS cloud, we can access your database from anywhere in the world.
Features of RDS
- Availability and Durability
- Cost effectiveness
There are two ways for setting up a RDS database in an organization:-
- Managed service
- Unmanaged Service
The main difference between unmanaged and managed service are that whenever you will use unmanaged service, if database goes down then you won’t be able to recover your data back, whereas in case of managed service AWS backup your database and in case of any failover or in case database instance goes down then you can recover your database in case of Managed Service.
If you stop your database instance in AWS then it will automatically start in every 7 days(default) for performing the snapshot (BACKUP).
So, whenever you are working in an organization always use managed service as a part of best practice.
Install Mysql using unmanaged service on Linux-ubuntu (DO NOT DO THIS IN PRODUCTION ENVIRONMENT)
sudo apt update -y && sudo apt install mysql-server -y
How to connect with your installed Mysql : To connect with your database as an unmanaged service, use below command, enter your database password in next line for security purpose.
Here -h defines a host machine where your database gets installed either on local machine or remote machine, if it is a remote machine then give the IP of that machine as a host.
-u defines, user name and -p defines password.
mysql -h localhost -u (username) -p Enter Password: ******
TO SETUP RDS AS A MANAGED SERVICE FOLLOW THE BELOW STEPS:-
Step 1: Go to your AWS console and click on service and select RDS from there.
Step 2: Click on create database
We are using mysql for demo purpose as it comes under free tier.
Step 3: Scroll down and fill the DB instance name, username and password for your database
Step 4: In additional configuration we are using public accessibility as YES, but do not use this in production setup, as YES.
Step 5: Scroll down to advance configuration and set up the backup retention period, by default it is 7 days, you can choose your own no. of days.
Step 6: After that click on create
Step 7: To obtain your instance endpoint click in db instance name.
This will be your database endpoint.
CONNECT TO YOUR DATABASE
For installing mysql client on ubuntu use below command so that you can connect with your database.
sudo apt install mysql-client -y
To connect to your database execute the below command:
mysql -h (database-endpoint) -u (username) -p (password)
TAKE SNAPSHOT/BACKUP OF YOUR DATABASE
Step 1: Select your db instance
Step 2: Go to Action tab
Step 3: Click on Take Snapshot and provide a name for your snapshot
Step 4: Click on Take Snapshot
To RESTORE SNAPSHOT
Step 1: Go to your snapshots
Step 2: Select your snapshot
Step 3: Go to Actions and select Restore snapshot
NOTE:- WHENEVER YOU WILL RECOVER YOUR DATA FROM YOUR SNAPSHOT IT WILL ALWAYS CREATE A NEW DATABASE INSTANCE.