标签:
对已经授过的用户权限进行修改。
我们知道:
grant 是授权命令,也可以进行授权后的权限修改操作
注意,
修改权限的时候,可以直接使用identified by password ,保持之前的密码不变!
一般我们grant授权的时候,使用identitied by,后面跟的是明文密码,生成后在mysql.user表里查询账号信息显示的才是密文密码
但是grant授权时,也可以在identified by 后面加password,这样后面设置的就是密文密码
有的时候,由开发人员先自己生成密文密码,即他们现在自己测试机上创建密码,查询到密文密码,然后将密文密码给我们运维人员进行grant授权,
这样给他们授权的密码只有他们自己知道,我们运维人员也是不知道的。
revoke 是回收权限命令(可以回收全部/或者部分权限)
flush privileges 是刷新权限表
show grants 是查看root用户权限
show grants for username@‘IP‘ 查看普通用户权限
使用revoke回收部分权限
回收除了select之外的所有权限
USAGE是默认的初始状态,表示无任何权限!!
mysql> show grants for xqshijie_test@‘61.148.60.42‘;
+-------------------------------------------------------------------------------------------------------------------------+
| Grants for xqshijie_test@61.148.60.42 |
+-------------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO ‘xqshijie_test‘@‘61.148.60.42‘ IDENTIFIED BY PASSWORD ‘*6DE35F444D5E33C31295A5D891098CD40229D9D9‘ |
| GRANT SELECT, INSERT, UPDATE, DELETE ON `zh_o2o_db`.* TO ‘xqshijie_test‘@‘61.148.60.42‘ |
+-------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> REVOKE INSERT, UPDATE, DELETE ON `zh_o2o_db`.* FROM ‘xqshijie_test‘@‘61.148.60.42‘;
Query OK, 0 rows affected (0.00 sec)
这下,就只剩下select查询权限了!!!
mysql> show grants for xqshijie_test@‘61.148.60.42‘;
+-------------------------------------------------------------------------------------------------------------------------+
| Grants for xqshijie_test@61.148.60.42 |
+-------------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO ‘xqshijie_test‘@‘61.148.60.42‘ IDENTIFIED BY PASSWORD ‘*6DE35F444D5E33C31295A5D891098CD40229D9D9‘ |
| GRANT SELECT ON `zh_o2o_db`.* TO ‘xqshijie_test‘@‘61.148.60.42‘ |
+-------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
也可以使用grant修改权限,修改后的权限会直接覆盖之前的权限
修改权限的时候,可以直接使用查看的密文
如下,添加update数据库权限,添加后之前的权限被覆盖!
mysql> show grants for xqshijie_test@‘124.65.197.154‘;
+---------------------------------------------------------------------------------------------------------------------------+
| Grants for xqshijie_test@124.65.197.154 |
+---------------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO ‘xqshijie_test‘@‘124.65.197.154‘ IDENTIFIED BY PASSWORD ‘*6DE35F444D5E33C31295A5D891098CD40229D9D9‘ |
| GRANT SELECT ON `fanghu_db`.* TO ‘xqshijie_test‘@‘124.65.197.154‘ |
| GRANT SELECT ON `xqsj_db`.* TO ‘xqshijie_test‘@‘124.65.197.154‘ |
| GRANT SELECT `zh_o2o_db`.* TO ‘xqshijie_test‘@‘124.65.197.154‘ |
+---------------------------------------------------------------------------------------------------------------------------+
4 rows in set (0.00 sec)
mysql> GRANT SELECT,UPDATE ON fanghu_db.* TO xqshijie_test@‘124.65.197.154‘ IDENTIFIED BY PASSWORD ‘*6DE35F444D5E33C31295A5D891098CD40229D9D9‘;
mysql> GRANT SELECT,UPDATE ON xqsj_db.* TO xqshijie_test@‘124.65.197.154‘ IDENTIFIED BY PASSWORD ‘*6DE35F444D5E33C31295A5D891098CD40229D9D9‘;
mysql> GRANT SELECT,UPDATE ON zh_o2o_db.* TO xqshijie_test@‘124.65.197.154‘ IDENTIFIED BY PASSWORD ‘*6DE35F444D5E33C31295A5D891098CD40229D9D9‘;
mysql> FLUSH PRIVILEGES;
mysql> show grants for xqshijie_test@‘124.65.197.154‘;
+---------------------------------------------------------------------------------------------------------------------------+
| Grants for xqshijie_test@124.65.197.154 |
+---------------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO ‘xqshijie_test‘@‘124.65.197.154‘ IDENTIFIED BY PASSWORD ‘*6DE35F444D5E33C31295A5D891098CD40229D9D9‘ |
| GRANT SELECT,UPDATE ON `fanghu_db`.* TO ‘xqshijie_test‘@‘124.65.197.154‘ |
| GRANT SELECT,UPDATE ON `xqsj_db`.* TO ‘xqshijie_test‘@‘124.65.197.154‘ |
| GRANT SELECT,UPDATE `zh_o2o_db`.* TO ‘xqshijie_test‘@‘124.65.197.154‘ |
+---------------------------------------------------------------------------------------------------------------------------+
4 rows in set (0.00 sec)
标签:
原文地址:http://www.cnblogs.com/kevingrace/p/5719536.html