0) open mysql on terminal
open terminal and type command
sudo mysql
entre password
1) Show Database
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| new |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
2) Change database
mysql> use new;
Database changed
3) Create Table
mysql> create table person(sno varchar(5) primary key, name varchar(20), age int(3), sex varchar(1));
Query OK, 0 rows affected (0.01 sec)
4) show Table
mysql> show tables;
+---------------+
| Tables_in_new |
+---------------+
| person |
+---------------+
1 row in set (0.00 sec)
5)Describe table
mysql> describe person;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| sno | varchar(5) | NO | PRI | NULL | |
| name | varchar(20) | YES | | NULL | |
| age | int(3) | YES | | NULL | |
| sex | varchar(1) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.02 sec)
6) insert value into table
mysql> insert into person (sno,name,age,sex) values ('1', 'subham', 25, 'M');
Query OK, 1 row affected (0.00 sec)
mysql> insert into person(sno,name,age,sex) values ('2', 'nunu', 30, 'F');
Qmysql> insert into person(sno,name,age,sex) values ('3', 'chayan', 20, 'M');
Query OK, 1 row affected (0.01 sec)
uery OK, 1 row affected (0.02 sec)
7) Show whole table
mysql> select *from person
-> ;
+-----+--------+------+------+
| sno | name | age | sex |
+-----+--------+------+------+
| 1 | subham | 25 | M |
| 2 | nunu | 30 | F |
| 3 | chayan | 20 | M |
+-----+--------+------+------+
3 rows in set (0.00 sec)
8) insert again values into table
mysql> insert into person(sno,name,age,sex) values ('4', 'debo', 15, 'M');
Query OK, 1 row affected (0.00 sec)
9) show table
mysql> select *from person;
+-----+--------+------+------+
| sno | name | age | sex |
+-----+--------+------+------+
| 1 | subham | 25 | M |
| 2 | nunu | 30 | F |
| 3 | chayan | 20 | M |
| 4 | debo | 15 | M |
+-----+--------+------+------+
4 rows in set (0.00 sec)
10) perform select operation
mysql> select sno from person where sno='2';
+-----+
| sno |
+-----+
| 2 |
+-----+
1 row in set (0.00 sec)
mysql> select sno from person;
+-----+
| sno |
+-----+
| 1 |
| 2 |
| 3 |
| 4 |
+-----+
4 rows in set (0.00 sec)
mysql> select name from person;
+--------+
| name |
+--------+
| subham |
| nunu |
| chayan |
| debo |
+--------+
4 rows in set (0.00 sec)
mysql> select *from person;
+-----+--------+------+------+
| sno | name | age | sex |
+-----+--------+------+------+
| 1 | subham | 25 | M |
| 2 | nunu | 30 | F |
| 3 | chayan | 20 | M |
| 4 | debo | 15 | M |
+-----+--------+------+------+
4 rows in set (0.01 sec)
mysql> select sno,age,sex from person where name='subham';
+-----+------+------+
| sno | age | sex |
+-----+------+------+
| 1 | 25 | M |
+-----+------+------+
1 row in set (0.01 sec)
mysql> select age from person;
+------+
| age |
+------+
| 25 |
| 30 |
| 20 |
| 15 |
+------+
4 rows in set (0.00 sec)
mysql> select name from person where age=30;
+------+
| name |
+------+
| nunu |
+------+
1 row in set (0.00 sec)
11) alter table
mysql> alter table person add phone varchar(10);
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table person add email varchar(20) after age;
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table person add adress varchar(20) after phone;
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0
12) show table after alter
mysql> describe person;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| sno | varchar(5) | NO | PRI | NULL | |
| name | varchar(20) | YES | | NULL | |
| age | int(3) | YES | | NULL | |
| email | varchar(20) | YES | | NULL | |
| sex | varchar(1) | YES | | NULL | |
| phone | varchar(10) | YES | | NULL | |
| adress | varchar(20) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
7 rows in set (0.00 sec)
13) show person
mysql> select *from person;
+-----+--------+------+-------+------+-------+--------+
| sno | name | age | email | sex | phone | adress |
+-----+--------+------+-------+------+-------+--------+
| 1 | subham | 25 | NULL | M | NULL | NULL |
| 2 | nunu | 30 | NULL | F | NULL | NULL |
| 3 | chayan | 20 | NULL | M | NULL | NULL |
| 4 | debo | 15 | NULL | M | NULL | NULL |
+-----+--------+------+-------+------+-------+--------+
4 rows in set (0.00 sec)
14) modify table
mysql> alter table person modify email varchar(30);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
15) describe table after modify
mysql> describe person;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| sno | varchar(5) | NO | PRI | NULL | |
| name | varchar(20) | YES | | NULL | |
| age | int(3) | YES | | NULL | |
| email | varchar(30) | YES | | NULL | |
| sex | varchar(1) | YES | | NULL | |
| phone | varchar(10) | YES | | NULL | |
| adress | varchar(20) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
7 rows in set (0.00 sec)
15) perform modify again
mysql> alter table person modify adress varchar(30);
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
16) describe person
mysql> describe person;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| sno | varchar(5) | NO | PRI | NULL | |
| name | varchar(20) | YES | | NULL | |
| age | int(3) | YES | | NULL | |
| email | varchar(30) | YES | | NULL | |
| sex | varchar(1) | YES | | NULL | |
| phone | varchar(10) | YES | | NULL | |
| adress | varchar(30) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
7 rows in set (0.00 sec)
17) drop one attributes
mysql> alter table person drop adress;
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0
18) describe person after drop one attribute
mysql> describe person;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| sno | varchar(5) | NO | PRI | NULL | |
| name | varchar(20) | YES | | NULL | |
| age | int(3) | YES | | NULL | |
| email | varchar(30) | YES | | NULL | |
| sex | varchar(1) | YES | | NULL | |
| phone | varchar(10) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
19)update table
mysql> update person set age=25;
Query OK, 4 rows affected (0.02 sec)
Rows matched: 5 Changed: 4 Warnings: 0
mysql> update person set sex='M';
Query OK, 1 row affected (0.02 sec)
Rows matched: 5 Changed: 1 Warnings: 0
20) show table
mysql> select *from person;
+-----+--------+------+----------------------+------+------------+
| sno | name | age | email | sex | phone |
+-----+--------+------+----------------------+------+------------+
| 1 | subham | 25 | NULL | M | NULL |
| 2 | nunu | 25 | NULL | M | NULL |
| 3 | chayan | 25 | NULL | M | NULL |
| 4 | debo | 25 | NULL | M | NULL |
| 5 | joy | 25 | iamsubham1@gmail.com | M | 8981887507 |
+-----+--------+------+----------------------+------+------------+
5 rows in set (0.00 sec
21) perform delete operation
mysql> delete from person where sno='4';
Query OK, 1 row affected (0.01 sec)
mysql> select *from person;
+-----+--------+------+----------------------+------+------------+
| sno | name | age | email | sex | phone |
+-----+--------+------+----------------------+------+------------+
| 1 | subham | 25 | NULL | M | NULL |
| 2 | nunu | 25 | NULL | M | NULL |
| 3 | chayan | 25 | NULL | M | NULL |
| 5 | joy | 25 | iamsubham1@gmail.com | M | 8981887507 |
+-----+--------+------+----------------------+------+------------+
4 rows in set (0.01 sec)
mysql> describe person;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| sno | varchar(5) | NO | PRI | NULL | |
| name | varchar(20) | YES | | NULL | |
| age | int(3) | YES | | NULL | |
| email | varchar(30) | YES | | NULL | |
| sex | varchar(1) | YES | | NULL | |
| phone | varchar(10) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
22) delete whole table values
mysql> delete from person;
Query OK, 4 rows affected (0.01 sec)
mysql> select *from person;
Empty set (0.00 sec)
23) drop whole table
mysql> drop table person;
Query OK, 0 rows affected (0.01 sec)
mysql> show tables;
Empty set (0.00 sec)
mysql> describe person;
ERROR 1146 (42S02): Table 'new.person' doesn't exist
mysql> select *from person;
ERROR 1146 (42S02): Table 'new.person' doesn't exist
24) exit mysql on terminal
mysql> exit
Bye
open terminal and type command
sudo mysql
entre password
1) Show Database
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| new |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
2) Change database
mysql> use new;
Database changed
3) Create Table
mysql> create table person(sno varchar(5) primary key, name varchar(20), age int(3), sex varchar(1));
Query OK, 0 rows affected (0.01 sec)
4) show Table
mysql> show tables;
+---------------+
| Tables_in_new |
+---------------+
| person |
+---------------+
1 row in set (0.00 sec)
5)Describe table
mysql> describe person;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| sno | varchar(5) | NO | PRI | NULL | |
| name | varchar(20) | YES | | NULL | |
| age | int(3) | YES | | NULL | |
| sex | varchar(1) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.02 sec)
6) insert value into table
mysql> insert into person (sno,name,age,sex) values ('1', 'subham', 25, 'M');
Query OK, 1 row affected (0.00 sec)
mysql> insert into person(sno,name,age,sex) values ('2', 'nunu', 30, 'F');
Qmysql> insert into person(sno,name,age,sex) values ('3', 'chayan', 20, 'M');
Query OK, 1 row affected (0.01 sec)
uery OK, 1 row affected (0.02 sec)
7) Show whole table
mysql> select *from person
-> ;
+-----+--------+------+------+
| sno | name | age | sex |
+-----+--------+------+------+
| 1 | subham | 25 | M |
| 2 | nunu | 30 | F |
| 3 | chayan | 20 | M |
+-----+--------+------+------+
3 rows in set (0.00 sec)
8) insert again values into table
mysql> insert into person(sno,name,age,sex) values ('4', 'debo', 15, 'M');
Query OK, 1 row affected (0.00 sec)
9) show table
mysql> select *from person;
+-----+--------+------+------+
| sno | name | age | sex |
+-----+--------+------+------+
| 1 | subham | 25 | M |
| 2 | nunu | 30 | F |
| 3 | chayan | 20 | M |
| 4 | debo | 15 | M |
+-----+--------+------+------+
4 rows in set (0.00 sec)
10) perform select operation
mysql> select sno from person where sno='2';
+-----+
| sno |
+-----+
| 2 |
+-----+
1 row in set (0.00 sec)
mysql> select sno from person;
+-----+
| sno |
+-----+
| 1 |
| 2 |
| 3 |
| 4 |
+-----+
4 rows in set (0.00 sec)
mysql> select name from person;
+--------+
| name |
+--------+
| subham |
| nunu |
| chayan |
| debo |
+--------+
4 rows in set (0.00 sec)
mysql> select *from person;
+-----+--------+------+------+
| sno | name | age | sex |
+-----+--------+------+------+
| 1 | subham | 25 | M |
| 2 | nunu | 30 | F |
| 3 | chayan | 20 | M |
| 4 | debo | 15 | M |
+-----+--------+------+------+
4 rows in set (0.01 sec)
mysql> select sno,age,sex from person where name='subham';
+-----+------+------+
| sno | age | sex |
+-----+------+------+
| 1 | 25 | M |
+-----+------+------+
1 row in set (0.01 sec)
mysql> select age from person;
+------+
| age |
+------+
| 25 |
| 30 |
| 20 |
| 15 |
+------+
4 rows in set (0.00 sec)
mysql> select name from person where age=30;
+------+
| name |
+------+
| nunu |
+------+
1 row in set (0.00 sec)
11) alter table
mysql> alter table person add phone varchar(10);
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table person add email varchar(20) after age;
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table person add adress varchar(20) after phone;
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0
12) show table after alter
mysql> describe person;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| sno | varchar(5) | NO | PRI | NULL | |
| name | varchar(20) | YES | | NULL | |
| age | int(3) | YES | | NULL | |
| email | varchar(20) | YES | | NULL | |
| sex | varchar(1) | YES | | NULL | |
| phone | varchar(10) | YES | | NULL | |
| adress | varchar(20) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
7 rows in set (0.00 sec)
13) show person
mysql> select *from person;
+-----+--------+------+-------+------+-------+--------+
| sno | name | age | email | sex | phone | adress |
+-----+--------+------+-------+------+-------+--------+
| 1 | subham | 25 | NULL | M | NULL | NULL |
| 2 | nunu | 30 | NULL | F | NULL | NULL |
| 3 | chayan | 20 | NULL | M | NULL | NULL |
| 4 | debo | 15 | NULL | M | NULL | NULL |
+-----+--------+------+-------+------+-------+--------+
4 rows in set (0.00 sec)
14) modify table
mysql> alter table person modify email varchar(30);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
15) describe table after modify
mysql> describe person;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| sno | varchar(5) | NO | PRI | NULL | |
| name | varchar(20) | YES | | NULL | |
| age | int(3) | YES | | NULL | |
| email | varchar(30) | YES | | NULL | |
| sex | varchar(1) | YES | | NULL | |
| phone | varchar(10) | YES | | NULL | |
| adress | varchar(20) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
7 rows in set (0.00 sec)
15) perform modify again
mysql> alter table person modify adress varchar(30);
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
16) describe person
mysql> describe person;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| sno | varchar(5) | NO | PRI | NULL | |
| name | varchar(20) | YES | | NULL | |
| age | int(3) | YES | | NULL | |
| email | varchar(30) | YES | | NULL | |
| sex | varchar(1) | YES | | NULL | |
| phone | varchar(10) | YES | | NULL | |
| adress | varchar(30) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
7 rows in set (0.00 sec)
17) drop one attributes
mysql> alter table person drop adress;
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0
18) describe person after drop one attribute
mysql> describe person;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| sno | varchar(5) | NO | PRI | NULL | |
| name | varchar(20) | YES | | NULL | |
| age | int(3) | YES | | NULL | |
| email | varchar(30) | YES | | NULL | |
| sex | varchar(1) | YES | | NULL | |
| phone | varchar(10) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
19)update table
mysql> update person set age=25;
Query OK, 4 rows affected (0.02 sec)
Rows matched: 5 Changed: 4 Warnings: 0
mysql> update person set sex='M';
Query OK, 1 row affected (0.02 sec)
Rows matched: 5 Changed: 1 Warnings: 0
20) show table
mysql> select *from person;
+-----+--------+------+----------------------+------+------------+
| sno | name | age | email | sex | phone |
+-----+--------+------+----------------------+------+------------+
| 1 | subham | 25 | NULL | M | NULL |
| 2 | nunu | 25 | NULL | M | NULL |
| 3 | chayan | 25 | NULL | M | NULL |
| 4 | debo | 25 | NULL | M | NULL |
| 5 | joy | 25 | iamsubham1@gmail.com | M | 8981887507 |
+-----+--------+------+----------------------+------+------------+
5 rows in set (0.00 sec
21) perform delete operation
mysql> delete from person where sno='4';
Query OK, 1 row affected (0.01 sec)
mysql> select *from person;
+-----+--------+------+----------------------+------+------------+
| sno | name | age | email | sex | phone |
+-----+--------+------+----------------------+------+------------+
| 1 | subham | 25 | NULL | M | NULL |
| 2 | nunu | 25 | NULL | M | NULL |
| 3 | chayan | 25 | NULL | M | NULL |
| 5 | joy | 25 | iamsubham1@gmail.com | M | 8981887507 |
+-----+--------+------+----------------------+------+------------+
4 rows in set (0.01 sec)
mysql> describe person;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| sno | varchar(5) | NO | PRI | NULL | |
| name | varchar(20) | YES | | NULL | |
| age | int(3) | YES | | NULL | |
| email | varchar(30) | YES | | NULL | |
| sex | varchar(1) | YES | | NULL | |
| phone | varchar(10) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
22) delete whole table values
mysql> delete from person;
Query OK, 4 rows affected (0.01 sec)
mysql> select *from person;
Empty set (0.00 sec)
23) drop whole table
mysql> drop table person;
Query OK, 0 rows affected (0.01 sec)
mysql> show tables;
Empty set (0.00 sec)
mysql> describe person;
ERROR 1146 (42S02): Table 'new.person' doesn't exist
mysql> select *from person;
ERROR 1146 (42S02): Table 'new.person' doesn't exist
24) exit mysql on terminal
mysql> exit
Bye
Comments
Post a Comment