SQL DCL Commands GRANT, REVOKE
SQL DCL Commands (GRANT, REVOKE)
1. AIM
To study and implement SQL Data Control Language (DCL) commands — GRANT and REVOKE — for managing database user permissions in MySQL.
2. THEORY
DCL commands are used to control access to data in the database.
✔ Major DCL Commands
| Command | Purpose |
|---|---|
| GRANT | Gives a user specific privileges |
| REVOKE | Removes previously granted privileges |
These commands allow the database administrator to manage security, access control, and permissions.
3. COMMON PRIVILEGES IN MYSQL
| Privilege | Meaning |
|---|---|
| SELECT | Allows reading data |
| INSERT | Allows inserting records |
| UPDATE | Allows updating records |
| DELETE | Allows deleting records |
| ALL PRIVILEGES | Gives full permissions |
| CREATE | Create tables |
| DROP | Drop tables |
| ALTER | Modify tables |
4. PREPARATION FOR LAB
Create a Sample Database and Table
5. DCL COMMANDS WITH EXAMPLES
Experiment 1: Creating a New User
✔ A user student1 is created on the local machine.
Experiment 2: GRANT Privileges
Example 1 — Grant SELECT privilege
Student1 can now view the table but cannot insert/update/delete.
Example 2 — Grant multiple privileges
Example 3 — Grant ALL PRIVILEGES
✔ Student1 can now perform any operation inside the database.
Apply privileges using FLUSH
Experiment 3: REVOKE Privileges
Example 1 — Revoke a specific privilege
Student1 can no longer insert rows.
Example 2 — Revoke all privileges
This removes all permissions granted earlier.
Experiment 4: Deleting a User
(Optional for lab)
6. LAB PRACTICE EXERCISES
- Create a user labuser and give only SELECT privileges on employees table.
- Revoke SELECT privilege and check access.
- Give INSERT and UPDATE privileges to a new user and test them.
- Grant ALL PRIVILEGES on the database to a user and later revoke only DELETE permission.
- Create two users and assign different privileges to compare their permissions.
- Try accessing restricted operations and observe the MySQL error messages.
7. RESULT
Students successfully learned how to manage user permissions using GRANT and REVOKE commands.
They understood how MySQL controls security and access at database and table levels.
Comments
Post a Comment