mysql grant USAGE ON 探究
(2011-01-11 10:48:06)
标签:
mysqlgrantrevoke |
分类: mysql |
1.今天需要修改线上数据库权限,查看某账号权限如下:
>show grants for community@localhost;
+-----------------------------------------------------------------------------------------+
| Grants for community@localhost |
+-----------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'community'@'localhost' IDENTIFIED BY
PASSWORD '565491d704013245' |
| GRANT ALL PRIVILEGES ON `community`.* TO 'community'@'localhost'
|
| GRANT ALL PRIVILEGES ON `mysql`.`componet` TO
'community'@'localhost' |
+-----------------------------------------------------------------------------------------+
然后纠结于GRANT USAGE ON是什么意思,在虚拟环境下创建了如上账号:
> grant usage on *.* to community@localhost identified by password '123456';
回收权限:revoke .. on .. from ..
> revoke all on `mysql`.`componet` from 'community'@'localhost' ;
对于GRANT USAGE ON,查看手册有如下介绍和实例:
mysql> GRANT USAGE ON *.* TO 'dummy'@'localhost';
修改community@localhost权限为select
原来权限为:
mysql> show grants for community@localhost;
+-----------------------------------------------------------------------------------------+
| Grants for community@localhost |
+-----------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'community'@'localhost' IDENTIFIED BY
PASSWORD '565491d704013245' |
| GRANT ALL PRIVILEGES ON `community`.* TO 'community'@'localhost'
|
| GRANT ALL PRIVILEGES ON `componet`.* TO 'community'@'localhost'
|
+-----------------------------------------------------------------------------------------+
修改权限语句为:
mysql> grant select on componet.* to
community@localhost;
Query OK, 0 rows affected (0.00 sec)
mysql> grant select on community.* to
community@localhost;
Query OK, 0 rows affected (0.00 sec)
查看权限---为什么没变呀
mysql> show grants for community@localhost;
+-----------------------------------------------------------------------------------------+
| Grants for community@localhost |
+-----------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'community'@'localhost' IDENTIFIED BY
PASSWORD '565491d704013245' |
| GRANT ALL PRIVILEGES ON `community`.* TO 'community'@'localhost'
|
| GRANT ALL PRIVILEGES ON `componet`.* TO 'community'@'localhost'
|
+-----------------------------------------------------------------------------------------+
3 rows in set (0.00 sec)
>flush privileges;一样的呀。
grant只是用于授权,实际上还是对mysql.user表的权限列值进行修改操作,all
privileges已经导致所有权限列值为‘Y’,再授予select权限也只对再次修改Select_priv:
Y,当然不会删除其他权限,那么只能revoke在grant了
mysql> revoke all privileges
on community.* from community@localhost;
Query OK, 0 rows affected (0.00 sec)
mysql> revoke all privileges on componet.* from
community@localhost;
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for community@localhost;
+-----------------------------------------------------------------------------------------+
| Grants for community@localhost |
+-----------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'community'@'localhost' IDENTIFIED BY
PASSWORD '565491d704013245' |
+-----------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> grant select on community.* to
community@localhost;
Query OK, 0 rows affected (0.00 sec)
mysql> grant select on componet.* to
community@localhost;
Query OK, 0 rows affected (0.00 sec)