1)查看mysql中存在的用户
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
mysql> select user,host from mysql.user;
+------------+--------------------------+ | user | host | +------------+--------------------------+ | oldgirl | % | | wan | % | | wanlong | % | | rep | 10.10.10.% | | root | 10.10.10.% | | wan | 10.10.10.% | | wanlong | 10.10.10.% | | oldgril123 | 10.10.10.0 /255 .255.255.0 |
| root | 127.0.0.1 | | root | ::1 | | root | C67-X64-A8 | | backup | localhost | | root | localhost | +------------+--------------------------+ 13 rows in set (0.00 sec)
|
2)如何查看用户的授权
1
2
3
4
5
6
7
|
mysql> show grants for 'wanlong' @ '10.10.10.%' ;
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Grants for wanlong@10.10.10.% |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | GRANT SELECT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'wanlong' @ '10.10.10.%' |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
|
3)all privileges具备哪些权限
a、创建测试账号并进行授权:
1
2
3
4
5
6
7
8
9
10
11
|
mysql> create user wanlong identified by 'wanlong' ;
Query OK, 0 rows affected (0.01 sec) mysql> grant all privileges on *.* to 'wanlong' @ '10.10.10.%' ;
Query OK, 0 rows affected (0.00 sec) mysql> show grants for 'wanlong' @ '10.10.10.%' ;
+-------------------------------------------------------+ | Grants for wanlong@10.10.10.% |
+-------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'wanlong' @ '10.10.10.%' |
+-------------------------------------------------------+ 1 row in set (0.00 sec)
|
b、回收insert权限,并查看用户的权限
1
2
3
4
5
6
7
8
9
10
11
|
mysql> revoke insert on *.* from 'wanlong' @ '10.10.10.%' ;
Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql> show grants for 'wanlong' @ '10.10.10.%' ;
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Grants for wanlong@10.10.10.% |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | GRANT SELECT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'wanlong' @ '10.10.10.%' |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
|
c、导出文件,并查看授权(all privileges还需要添加刚才使用revoke取消的insert授权)
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
|
# mysql -uroot -predhat12345 -S /data/3306/mysql.sock -e "show grants for 'wanlong'@'10.10.10.%';"|grep -i grant|tail -1|tr ',' '\n'>all.privileges 查看all privileges具备的权限: # cat all.privileges GRANT SELECT UPDATE
DELETE
CREATE
DROP
RELOAD
SHUTDOWN
PROCESS
FILE
REFERENCES
INDEX
ALTER
SHOW DATABASES
SUPER
CREATE TEMPORARY TABLES
LOCK TABLES
EXECUTE
REPLICATION SLAVE
REPLICATION CLIENT
CREATE VIEW
SHOW VIEW
CREATE ROUTINE
ALTER ROUTINE
CREATE USER
EVENT
TRIGGER
CREATE TABLESPACE ON *.* TO 'wanlong' @ '10.10.10.%'
|
本文转自 冰冻vs西瓜 51CTO博客,原文链接:http://blog.51cto.com/molewan/1861834,如需转载请自行联系原作者