Skip to content

Commit 1f70419

Browse files
committed
securing database users and priviliges
1 parent 0485b6e commit 1f70419

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*******************************************/
2+
/* Creating a user */
3+
/*******************************************/
4+
5+
/* with IP address */
6+
CREATE USER john@127.0.0.1;
7+
8+
/* with Host name */
9+
CREATE USER john@localhost;
10+
11+
CREATE USER john@sample.com;
12+
13+
-- from any subdomain of sample.com
14+
CREATE USER john@'%.sample.com';
15+
16+
/* can access from anywhere with this name */
17+
CREATE USER john IDENTIFIED BY '1234';
18+
19+
20+
/*******************************************/
21+
/* View users */
22+
/*******************************************/
23+
24+
SELECT * FROM mysql.user;
25+
26+
27+
/*******************************************/
28+
/* Dropping users */
29+
/*******************************************/
30+
31+
DROP USER john;
32+
33+
/*******************************************/
34+
/* Changing password */
35+
/*******************************************/
36+
37+
-- set password for a specific user
38+
SET PASSWORD FOR john = '5678';
39+
40+
-- set password ourselves who ever is currently logged in
41+
SET PASSWORD = 'abcdefg';
42+
43+
/*******************************************/
44+
/* Granting Priviliges */
45+
/*******************************************/
46+
47+
-- Scenerio 1) web/desktop application
48+
CREATE USER awesome_app IDENTIFIED BY '1234';
49+
50+
-- execute means able to use stored procedures
51+
/*
52+
GRANT ....
53+
ON database_name.table_name (or * for every tables)
54+
TO username;
55+
*/
56+
GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE
57+
ON mosh_sql_store.*
58+
TO awesome_app;
59+
60+
-- Scenerio 2) Admin User
61+
/*
62+
GRANT ALL (all means every priviliges)
63+
ON *.* (every database and every tables)
64+
TO username;
65+
*/
66+
GRANT ALL
67+
ON *.*
68+
TO john;
69+
70+
71+
/*******************************************/
72+
/* Viewing Priviliges */
73+
/*******************************************/
74+
SHOW GRANTS FOR john;
75+
76+
-- for current user
77+
SHOW GRANTS;
78+
79+
/*******************************************/
80+
/* Revoking Priviliges */
81+
/*******************************************/
82+
83+
GRANT CREATE VIEW
84+
ON sql_store.*
85+
TO awesome_app;
86+
87+
-- now made mistake and want to revoke
88+
REVOKE CREATE VIEW
89+
ON sql_store.*
90+
FROM awesome_app;

0 commit comments

Comments
 (0)