17-02-24 Database (Chargeable Service)
17-02-24 Database (Chargeable Service)
● Platform as a service(PaaS)
● It is a container filled with information/data which is electronically stored in a
server/computer.
● Used to store customer data.
● Store data in various formats in DBMS: Types of DBMS:
○ Structured format
■ RDS - schema based storage
○ Semi structured format
■ Type of structured data but does not have table format
■ It will follow some structure
■ Eg:MongoDB, email, json etc
○ Unstructured format
■ No structure
■ Manual upload
■ eg: hadoop, tableau
● Collection of data.
● Data can be of any format - text, image, video, audio etc
● This is chargeable. S3 is free. Why not use S3 for everything?
○ Better usage of CRUD operations -> read, update, insert, alter, drop, delete etc
■ Eg: Customer data (login details) are verified and updated when
necessary.
○ Handles customer’s sensitive information - So DB must always be in the
private network. (public network will have homepage and other things the
public can view)
● Mandatory:
○ Enable accidental termination
○ Must have username and password
● Works on vertical scaling
● What data is stored in the database?
○ Application data
○ User data
● Our database must always have a replica DB (secondary database).
● These 2 databases must always be in sync with each other.
○ How is the sync done?
■ Automatically by AWS
■ No manual intervention required
● This replica is placed in a different region (For safety. If the databases in one region
goes down the database in another region can take position)
● Database Permission:
○ It only has read and write permission
○ No execute permission
● The replica will only have read permission
○ Whatever data written in the primary db is automatically replicated in the
secondary database.
○ So there is no need for write permission
● When the primary db goes down and the secondary db takes position as primary db
○ It will automatically get write permission as well.
● Is database the same as DBMS?
● DB - Container to store data
● DBMS - Software used to manage the database.
Relational database
● Used to store structured data
● SQL
○ Structured query language
○ Developed by IBM
○ Declarative language - because they maintain well defined standards
○ Invented in the 1970’s
Creation
● Create private network: RDS - manage relational database service - left dashboard
(subnet groups) - Create DB subnet group (take default network as private network as of
now - bc we did not learn VPC yet.) - name: pvt-network - Description: Network for DB -
VPC (select default) - select us-east-2a and 2b -select 2 subnets - create
● RDS - databases - create database - Standard create - MySQL - Templates: free tier -
Db instance identifier(used to identify db in RDS area): primary-db - admin - self
managed - password: admin123 - DB size: db.t3.micro - Additional Storage: uncheck
autoscaling - Don’t connect to EC2 instance - select default VPC - subnet group:
pvt-network(network u created above) - Public access: Yes - VPC: existing - default
(make sure you have All TCP or MYSQL enabled in security group) - availability zone:
us-east-2a (replicated db must be in another availability zone-us-east-2b. But as of now,
we are not replicating the db as it is chargeable. In real time, we will replicate)- Additional
configuration: initial database name: mydb(this name is used to connect via instance) -
enable automated backup - backup retention period: 1 - Backup Window: no preference
- Uncheck encryption (needed in real time, now chargeable) - Check backup replication -
uncheck maintenance (Used to update mysql automatically - like weekly once or based
on preferance) - no preference - uncheck enable deletion protection - create database.
Can take up to 10 minutes. Status: available
● Create an instance in same region - storage 30 GB
● Open db - connectivity and security: endpoint (this is the point where the read and write
take place)
● Connect the ec2 instance - username: root - connect
○ Terminal opens
○ >>>mysql –-version
○ >>>yum install mysql -y
○ >>>mysql –version
○ Mysql -h <paste endpoint here> -P 3306 -u admin -p
■ -h refers to host
■ -u refers username
■ -p refers to password
■ -P refers to port
○ Now you will be connected with mysql db
○ Open workbench in desktop
■ Connection name: myapp-db
■ Hostname: <paste endpoint>
■ Username: admin
■ Pasword: admin123
■ Port: 3307
○ You can run queries through the desktop application or the remote linux machine
(we connected in both)
○ Application
■ >>>Create database movies;
■ >>>Show databases
○ Remote Linux
■ >>>Create database author
■ Try to create a table, add rows, alter, update, delete etc
○ Now check for replica
■ Go to database in aws
● Actions - create read replica - create read replica - DB instance
identifier:replica-db - 20 GB - uncheck autoscaling - Additional
configuration:port number: 3307 - create read replica
■ ROLE:
● name: replica-db Role: Replica
● name: primary-db Role: Primary
■ You will get replica under primary db
■ Primary and replica will have the same endpoint
■ Same username and password for replica and primary
■ Delete primary-db - Role:Instance
AURORA DB(chargeable)
● Cluster based db
● Has separate endpoint for read and write operations
○ This will result in faster operations
○ Performance will be high
● Create aurora
○ RDS - create database - standard - aurora(mysql) - Templates: Dev/Test - DB
cluster identifier: aurora - username: admin - password: admin123 - Aurora
Standard - db.t3.medium - Don’t create replica - pvt-network - default VPC -
disable everything - create db
● Role:
○ A Cluster and the writer instance will be created.
○ When you go inside you will get 2 endpoints. Type: Writer and Reader endpoints
○ In mysql only one instance will be created
Stopping db
● What to do if you want to stop your db and still want to retain existing data
● DB - can stop temporarily but it will start after a while (chargeable)
● What to do?
○ Take a snapshot (less charge but if you don’t even want that do the below 2
steps)
○ Exports in Amazon S3
○ Move to archive mode in S3
○ Archive mode in S3 will hardly incur any charges
○ Similarly you can restore from S3 (RDS - database - restore from S3)
Deletion
● Delete db
● Delete subnet group
● Delete ec2