-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path36_Grant_Revoke.sql
More file actions
39 lines (25 loc) · 986 Bytes
/
36_Grant_Revoke.sql
File metadata and controls
39 lines (25 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
-- GRANT is used to give privileges/permissions to a user in MySQL.
-- Create a user
CREATE USER 'test_user'@'localhost' IDENTIFIED BY 'password123';
-- Granting SELECT and INSERT privileges on a specific database
GRANT SELECT, INSERT ON college.students TO 'test_user'@'localhost';
-- Granting ALL privileges on a specific table
GRANT ALL PRIVILEGES ON college.* TO 'test_user'@'localhost';
-- Granting ALL privileges on all databases
GRANT ALL PRIVILEGES ON *.* TO 'test_user'@'localhost';
-- Apply the changes
FLUSH PRIVILEGES;
-- REVOKE is used to remove privileges/permissions from a user in MySQL.
-- Remove specific privileges
REVOKE INSERT, UPDATE
ON college.students
FROM 'test_user'@'localhost';
-- Remove all privileges
REVOKE ALL PRIVILEGES, GRANT OPTION
FROM 'test_user'@'localhost';
-- After revoke, run this
FLUSH PRIVILEGES;
-- Dropping the user
DROP USER 'test_user'@'localhost';
-- Check the privileges of a user
SHOW GRANTS FOR 'test_user'@'localhost';