Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Assignment 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Assignment 1 

AIM: ​Study of Open Source Relational Databases : MySQL

​OBJECTIVES: ​Study of Open Source Relational Databases : MySQL

Theory:

MySQL is a Relational Management Database System(RDBMS), and ships with no GUI tools to
administer MySQL databases or manage data contained within the databases. Users may use the included
Command line tools, or use MySQL "front-ends", desktop software and web applications that create and
manage MySQL databases, build database structures, back up data, inspect status, and work with data
records. The official set of MySQL front-end tools, MySQL workbench is actively developed by Oracle,
and is freely available for use.

Client server system has one or more client process and one or more server processes,and a client process
can send a query to any one server process.Clients are responsible for user-interface issues,and servers
manages data and execute transaction .Thus, aclient process could run on a personal computer and send
queries to a server to a server running on a mainframe.

Components of SQL:

1) DDL (Data Definition Language)

-This SQL syntax is used to create, modify and delete database structures.DDL syntax cannot be
applied to the manipulation of business data.DDL is almost always used by the database administrator, a
database schema implementer or an application developer. Every DDL command implicitly issues a
COMMIT making permanent all changes in the database.

Examples:
● CREATE: ​Create objects in database schema.
● ALTER: ​Alters the structure of objects that exist within the database schema.
● DROP: ​Drops objects that exist within database schema.
● TRUNCATE: ​Removes all records from a table, including all space allocated for the records.
● COMMENT:​Adds comments ,generally used for proper documentation of a database schema.

2)DML(Data Manipulation Language)


-​It is the SQL syntax that allows manipulating data within database tables.
Examples:​ INSERT, UPDATE, DELETE.
3)DCL(Data Control Language)
-​It controls access to the database and table data. Occasionally DCL statements are
grouped with DML statements.

Examples:
COMMIT,SAVEPOINT,ROLLBACK,SET TRANSACTION
● The commands used in MySQL are:

1) CREATE :

The CREATE command is used to create a database or create a table in a particular database.

i) FOR CREATING A DATABASE :

Syntax: create database database_name; //for creating a database

Example: create database Student_info //Student_info database is created

ii)FOR CREATINGA TABLE:


The table creation command requires:
Name of the table
Names of fields
Definitions for each field

Syntax: ​CREATE TABLE table_name (column_name1 column_type, column_name2


column_type,........);

​Example: ​create table Student(Roll_no tinyint PRIMARY KEY,Fname varchar(20) NOT NULL,Lname
varchar(20),Mob_no char(10));

2)ALTER:​MySQL​ALTER command is used to change a name of your table, any table field or if you
want to add or delete an existing column in a table.

Syntax:

i)DROP​- Used to delete a particular column.

Syntax​: mysql> ALTER TABLE table_name DROP i; //i is the row you want to delete.

ii)ADD​-Used to add a particular column to an existing table.

Syntax:​mysql> ALTER TABLE table_name ADD i int;

iii)CHANGE​- Used to change a column's definition, use ​MODIFY or ​CHANGE clause along with
ALTER command. After the CHANGE keyword, you name the column you want to change, then specify
the new definition, which includes the new name
​Syntax:

For example, to change column ​c​ from CHAR(1) to CHAR(10), do this:

mysql> ALTER TABLE table_name MODIFY c CHAR(10);

​mysql> ALTER TABLE testalter_tbl CHANGE i j BIGINT;

3)DELETE:​used to delete a record from any MySQL table, then you can use SQL command ​DELETE
FROM.

Syntax: DELETE FROM table_name [WHERE Clause]

INDEX: ​Indexing is the way of keeping table column data sorted so that searching and locating data
consumes less time. Hence indexes essentially improve the speed at which records can be located and
retrieved from a table.

Types of Index: ​SIMPLE INDEX: ​An index created on single column data is called Simple index.
COMPOSITE INDEX: ​An index created on multiple column data is called a composite index.

​1)​CREATE INDEX​: A database index is a data structure that improves the speed of operations in a
table. Indexes can be created using one or more columns, providing the basis for both rapid random
lookups and efficient ordering of access to records.

Syntax:

CREATE UNIQUE INDEX index_name ON table_name ( column1, column2,...);

2)​DELETE INDEX​: Used to delete any index.

Syntax:

mysql> ALTER TABLE table_name DROP INDEX (c);

VIEWS​: A view is a table whoes rows are not explicitly stored in the database but are computed as
needed from a view defination.To reduce redundant data to the minimum possible, MySQL allows
creation of an object called a view .A view is mapped to a SELECT statement. This technique offers a
simple, effective way of hiding columns of a table.
Example: CREATE
VIEW stud_info(name,sid,course)
AS SELECT S.name,S.sid,S.cid

FROM stud S,Enrolled E


WHERE S.sid AND E.grade='B'

1)​CREATE VIEW​: Used to create a view.

Syntax:

mysql> CREATE VIEW database_name.view_name AS SELECT * FROM table_name;

Example:

CREATE VIEW stud_info(name,sid,course)

AS SELECT S.name,S.sid,S.cid

FROM stud S,Enrolled E


WHERE S.sid AND E.grade='B'

2)​DELETE VIEW​: DROP view removes one or more views.

Syntax:

mysql>DROP view viewname;

Example:

DROP view stud_info;

Steps For creating client server connectivity:

To connecting client and server in a network we have to follows the following steps :
Server side Commands:

1] > sudo -i

It is used to open file my.cnf

2] $ nano /etc/mysql/my.cnf

In this step we have to search #bind_address command and after finding this command comment
that command then used following options
ctrl v : It is used to move next page.
ctrl o : It is used to save the changes.
ctrl x : It is used to exit from file

3] $ sudo service mySql restart;

4] $ mySql -u root -p;


It is used for login into mysql. then it is asked for the password. Enter the appropriate password.

5] mySql> grant all privileges on *.* to root@<client_IP> identified by "mysql" with grant
option;

Client side Commands:

1] > mySql -h<server_IP> -u root -p;

This commands is used to login into mysql database then enter the correct password.

2] mySql>create user <username>@ '%' ;

This command used for client for cereating the llogin and password.

Example:

mySql>create TEComp@ '%';

where,

% is used for any computer which are in network can access server data.

and if not then insted of % we can also pass the IP address for particular client.
3] mySql> grant all on *.* to TEComp@'%' ;

Exit

4] To connecting to the server used the following command:

$ mySql -h <server_IP> -u TEComp -p;

After that enter the user created password

Conclusion:

Thus we studied ​Open Source Relational Databases: MySQL​ successfully.

You might also like