Skip to content

Commit e16e764

Browse files
authored
update privilege management document (#3075) (#3175)
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
1 parent 9a649dd commit e16e764

File tree

1 file changed

+55
-38
lines changed

1 file changed

+55
-38
lines changed

privilege-management.md

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,7 @@ mysql> SELECT user,host,password FROM mysql.user WHERE user='idontexist';
8282
1 row in set (0.00 sec)
8383
```
8484

85-
> **Note:**
86-
>
87-
> Granting privileges to a database or table does not check if the database or table exists.
88-
89-
```sql
90-
mysql> SELECT * FROM test.xxxx;
91-
ERROR 1146 (42S02): Table 'test.xxxx' doesn't exist
92-
93-
mysql> GRANT ALL PRIVILEGES ON test.xxxx TO xxxx;
94-
Query OK, 0 rows affected (0.00 sec)
95-
96-
mysql> SELECT user,host FROM mysql.tables_priv WHERE user='xxxx';
97-
+------|------+
98-
| user | host |
99-
+------|------+
100-
| xxxx | % |
101-
+------|------+
102-
1 row in set (0.00 sec)
103-
```
104-
105-
You can use fuzzy matching to grant privileges to databases and tables.
85+
You can use fuzzy matching in `GRANT` to grant privileges to databases.
10686

10787
```sql
10888
mysql> GRANT ALL PRIVILEGES ON `te%`.* TO genius;
@@ -172,28 +152,35 @@ You can use the `SHOW GRANTS` statement to see what privileges are granted to a
172152

173153
```sql
174154
SHOW GRANTS; -- show grants for the current user
155+
156+
+-------------------------------------------------------------+
157+
| Grants for User |
158+
+-------------------------------------------------------------+
159+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION |
160+
+-------------------------------------------------------------+
175161
SHOW GRANTS FOR 'root'@'%'; -- show grants for a specific user
176162
```
177163

178-
To be more precise, you can check the privilege information in the `Grant` table. For example, you can use the following steps to check if the `test@%` user has the `Insert` privilege on `db1.t`:
179-
180-
1. Check if `test@%` has global `Insert` privilege:
164+
For example, create a user `rw_user@192.168.%` and grant the user with write privilege on the `test.write_table` table and global read privilege.
181165

182-
```sql
183-
SELECT Insert_priv FROM mysql.user WHERE user='test' AND host='%';
184-
```
185-
186-
2. If not, check if `test@%` has database-level `Insert` privilege at `db1`:
187-
188-
```sql
189-
SELECT Insert_priv FROM mysql.db WHERE user='test' AND host='%';
190-
```
166+
```sql
167+
CREATE USER `rw_user`@`192.168.%`;
168+
GRANT SELECT ON *.* TO `rw_user`@`192.168.%`;
169+
GRANT INSERT, UPDATE ON `test`.`write_table` TO `rw_user`@`192.168.%`;
170+
```
191171

192-
3. If the result is still empty, check whether `test@%` has table-level `Insert` privilege at `db1.t`:
172+
Show granted privileges of the `rw_user@192.168.%` user:
193173

194-
```sql
195-
SELECT table_priv FROM mysql.tables_priv WHERE user='test' AND host='%' AND db='db1';
196-
```
174+
```sql
175+
SHOW GRANTS FOR `rw_user`@`192.168.%`;
176+
177+
+------------------------------------------------------------------+
178+
| Grants for rw_user@192.168.% |
179+
+------------------------------------------------------------------+
180+
| GRANT Select ON *.* TO 'rw_user'@'192.168.%' |
181+
| GRANT Insert,Update ON test.write_table TO 'rw_user'@'192.168.%' |
182+
+------------------------------------------------------------------+
183+
```
197184

198185
## Privileges required for TiDB operations
199186

@@ -212,6 +199,8 @@ You can check privileges of TiDB users in the `INFORMATION_SCHEMA.USER_PRIVILEGE
212199
| Insert | `InsertPriv` | Inserts data to a table |
213200
| Update | `UpdatePriv` | Updates the table data |
214201
| Delete | `DeletePriv` | Deleted the table data |
202+
| Reload | `ReloadPriv` | Executes the `FLUSH` statement |
203+
| Config | `ConfigPriv` | Dynamically reloads configuration |
215204
| Trigger | `TriggerPriv` | / |
216205
| Process | `ProcessPriv` | Displays the running task |
217206
| Execute | `ExecutePriv` | Executes the `EXECUTE` statement |
@@ -268,6 +257,10 @@ Requires the `INDEX` privilege for the table.
268257

269258
Requires the `DROP` privilege for the table.
270259

260+
### LOAD DATA
261+
262+
Requires the `INSERT` privilege for the table.
263+
271264
### TRUNCATE TABLE
272265

273266
Requires the `DROP` privilege for the table.
@@ -286,6 +279,8 @@ Requires the `INSERT` and `SELECT` privileges for the table.
286279

287280
`SHOW CREATE VIEW` requires the `SHOW VIEW` privilege.
288281

282+
`SHOW GRANTS` requires the `SELECT` privilege to the `mysql` database. If the target user is current user, `SHOW GRANTS` does not require any privilege.
283+
289284
### CREATE ROLE/USER
290285

291286
`CREATE ROLE` requires the `CREATE ROLE` privilege.
@@ -306,9 +301,31 @@ Requires the `CREATE USER` privilege.
306301

307302
Requires the `GRANT` privilege with the privileges granted by `GRANT`.
308303

304+
Requires additional `CREATE USER` privilege to create a user implicitly.
305+
306+
`GRANT ROLE` requires `SUPER` privilege.
307+
309308
### REVOKE
310309

311-
Requires the `SUPER` privilege.
310+
Requires the `GRANT` privilege and those privileges targeted by the `REVOKE` statement.
311+
312+
`REVOKE ROLE` requires `SUPER` privilege.
313+
314+
### SET GLOBAL
315+
316+
Requires `SUPER` privilege to set global variables.
317+
318+
### ADMIN
319+
320+
Requires `SUPER` privilege.
321+
322+
### SET DEFAULT ROLE
323+
324+
Requires `SUPER` privilege.
325+
326+
### KILL
327+
328+
Requires `SUPER` privilege to kill other user sessions.
312329

313330
## Implementation of the privilege system
314331

0 commit comments

Comments
 (0)