Data Control Language
Aim:
To study about “Data Control Language” commands in Mysql.
Uses of DCL :
• It is used inorder to control various operations of the database objects.
• Two commands are supported by this language.
▪ Grant
▪ Revoke
➢ Grant: This command is used to grant permission on database objects from one user to
another user.
➢ Revoke: This command is used to cancel the given permission
MySQL server provides multiple types of privileges to a new user account. Some of the most
commonly used privileges are given below:
1. ALL PRIVILEGES: It permits all privileges to a new user account.
2. CREATE: It enables the user account to create databases and tables.
3. DROP: It enables the user account to drop databases and tables.
4. DELETE: It enables the user account to delete rows from a specific table.
5. INSERT: It enables the user account to insert rows into a specific table.
6. SELECT: It enables the user account to read a database.
7. UPDATE: It enables the user account to update table rows.
Syntax:
Grant <Permission List> on <table name> to <Users List>
Eg: Grant select, insert on students to kero;
GRANT ALL PRIVILEGES ON table name TO username;
Sometimes, you want to flush all the privileges of a user account for changes occurs
immediately, type the following command.
FLUSH PRIVILEGES;
If you want to see the existing privileges for the user, execute the following command.
mysql> SHOW GRANTS for username;
Revoke: This command is used to Cancel given permission
Syntax: Revoke <Pemission list> on <table name> from <user list>;
Eg: Revoke select, insert on student from user2;
Step 1 : Entering into Root:
Step 2: Create database:
Step 3: Using database:
Step 4: Create table students and describe table:
Step 5: Inserting records into table:
Step 6: Using Select Command, displaying the entire records of the table:
Step 7: Exit from college and Create User:
Step 8: Command to see the total number of users created:
Step 9: GRANT Permission to access the table with SELECT, INSERT AND UPDATE
command:
Step 10: Exit out from root:
Step 1: Now enter into newly created User:
Step 2: Use the database for inserting, updating and selecting the tables:
Step 3: Check for the permission of the tables (INSERT, UPDATE, SELECT):
Step 4: Other Commands like DELETE, ALTER etc will not work, because the GRANT
permission is not allowed these commands:
Step 5: Exit out from root:
Step 1: Again Log into root to REVOKE the permissions:
Step 2: Use the database to REVOKE permission:
Step 3: Exit from root and Log into user to check for permissions:
Step 1: Only the select will work, because its Grant is not revoked:
Results:
Hence the Data Control Language commands are successfully executed.