0% found this document useful (0 votes)
47 views

DB Lab Basics

The document shows the steps to connect to an AWS RDS MySQL database instance from an EC2 instance, create databases and tables, insert and query data. Specifically, it connects to the MySQL database, creates a database called "lab" and a table within it, inserts a sample record, and performs some queries. It then creates another database called "aws" and a table in the original database to hold session data, inserts some records, and queries the table.

Uploaded by

Anand K
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

DB Lab Basics

The document shows the steps to connect to an AWS RDS MySQL database instance from an EC2 instance, create databases and tables, insert and query data. Specifically, it connects to the MySQL database, creates a database called "lab" and a table within it, inserts a sample record, and performs some queries. It then creates another database called "aws" and a table in the original database to hold session data, inserts some records, and queries the table.

Uploaded by

Anand K
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

login as: ec2-user

Authenticating with public key "imported-openssh-key"


Last login: Thu Apr 14 06:34:16 2022 from 49.37.149.12

__| __|_ )
_| ( / Amazon Linux 2 AMI
___|\___|___|

https://aws.amazon.com/amazon-linux-2/
[ec2-user@ip-10-0-2-26 ~]$ man mysql
[ec2-user@ip-10-0-2-26 ~]$ sudo mysql -u admin -p --host lab-db.c1sguoc32lvh.us-
west-2.rds.amazonaws.com
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 23
Server version: 8.0.28 Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> show databases;


+--------------------+
| Database |
+--------------------+
| information_schema |
| lab |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)

MySQL [(none)]> use lab;


Database changed
MySQL [lab]> show tables;
Empty set (0.00 sec)

MySQL [lab]> create table lab(rollno int,name char(20),class int,section char(1)


);
Query OK, 0 rows affected (0.06 sec)

MySQL [lab]> show tables;


+---------------+
| Tables_in_lab |
+---------------+
| lab |
+---------------+
1 row in set (0.00 sec)

MySQL [lab]> desc lab;


+---------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+----------+------+-----+---------+-------+
| rollno | int | YES | | NULL | |
| name | char(20) | YES | | NULL | |
| class | int | YES | | NULL | |
| section | char(1) | YES | | NULL | |
+---------+----------+------+-----+---------+-------+
4 rows in set (0.00 sec)

MySQL [lab]> insert into lab values(100,'anand',10,'A');


Query OK, 1 row affected (0.01 sec)

MySQL [lab]> select * from lab;


+--------+-------+-------+---------+
| rollno | name | class | section |
+--------+-------+-------+---------+
| 100 | anand | 10 | A |
+--------+-------+-------+---------+
1 row in set (0.00 sec)

MySQL [lab]> select name from lab;


+-------+
| name |
+-------+
| anand |
+-------+
1 row in set (0.00 sec)

MySQL [lab]> select name,class from lab;


+-------+-------+
| name | class |
+-------+-------+
| anand | 10 |
+-------+-------+
1 row in set (0.00 sec)

MySQL [lab]>
Creating Another Database / Tables
MySQL [lab]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| lab |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)

MySQL [lab]> create database aws; (Database aws created)


Query OK, 1 row affected (0.00 sec)

MySQL [lab]> show databases;


+--------------------+
| Database |
+--------------------+
| aws |
| information_schema |
| lab |
| mysql |
| performance_schema |
| sys |
+--------------------+
6 rows in set (0.00 sec)

MySQL [lab]> create table sessions(session int,topic varchar(50),duration int(3));


Query OK, 0 rows affected, 1 warning (0.04 sec)

MySQL [lab]> show tables;


+---------------+
| Tables_in_lab |
+---------------+
| lab |
| sessions |
+---------------+
2 rows in set (0.00 sec)

MySQL [lab]> desc sessions;


+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| session | int | YES | | NULL | |
| topic | varchar(50) | YES | | NULL | |
| duration | int | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

MySQL [lab]> insert into sessions values(1,'DB Fundementals',4);


Query OK, 1 row affected (0.01 sec)

MySQL [lab]> insert into sessions values(2,'DB Lab',4);


Query OK, 1 row affected (0.01 sec)

MySQL [lab]> select * from sessions;


+---------+-----------------+----------+
| session | topic | duration |
+---------+-----------------+----------+
| 1 | DB Fundementals | 4 |
| 2 | DB Lab | 4 |
+---------+-----------------+----------+
2 rows in set (0.00 sec)

MySQL [lab]>

You might also like