当前位置:网站首页>用户和权限撤销用户权限
用户和权限撤销用户权限
2022-07-27 18:00:00 【华为云】
30.6 撤销用户权限
MySQL中既可以为用户添加权限,也可以撤销用户的权限。MySQL支持使用REVOKE语句撤销用户的权限,同时,也可以通过操作数据表来撤销用户的权限。
30.6.1 使用REVOKE语句撤销用户权限
REVOKE语句可以撤销用户的权限,其语法格式如下:
REVOKE priv_type [(column_list)] [, priv_type [(column_list)]] ... ON [object_type] priv_level FROM user_or_role [, user_or_role] ...REVOKE ALL [PRIVILEGES], GRANT OPTION FROM user_or_role [, user_or_role] ...REVOKE PROXY ON user_or_role FROM user_or_role [, user_or_role] ...REVOKE role [, role ] ... FROM user_or_role [, user_or_role ] ...user_or_role: { user (see Section 6.2.4, “Specifying Account Names”) | role (see Section 6.2.5, “Specifying Role Names”.}其中,部分参数说明如下:
·priv_type:表示权限的类型;
·column_list:表示撤回的权限作用于数据表中的哪些字段上,此参数可以省略,如果省略,则表示撤回的权限作用于整个数据表;
·FROM:表示对哪个用户执行撤回权限的操作。
(1)使用REVOKE语句撤销binghe_test用户对所有数据表的删除权限。
mysql> REVOKE DELETE ON *.* FROM 'binghe_test'@'localhost';Query OK, 0 rows affected (0.00 sec)SQL语句执行成功,查看binghe_test用户的数据库权限。
mysql> SHOW GRANTS FOR 'binghe_test'@'localhost';+------------------------------------------------------------------+| Grants for [email protected] |+------------------------------------------------------------------+| GRANT SELECT, INSERT, UPDATE ON *.* TO 'binghe_test'@'localhost' |+------------------------------------------------------------------+1 row in set (0.00 sec)此时,binghe_test用户对所有数据表的删除权限已经被撤销。
(2)REVOKE语句不能撤销用户的USAGE权限,也就是说,REVOKE语句不能删除MySQL中的用户,例如,MySQL中的binghe_login用户的权限如下:
mysql> SHOW GRANTS FOR 'binghe_login'@'localhost';+--------------------------------------------------+| Grants for [email protected] |+--------------------------------------------------+| GRANT USAGE ON *.* TO 'binghe_login'@'localhost' |+--------------------------------------------------+1 row in set (0.00 sec)结果显示,binghe_login用户只拥有登录MySQL的权限。使用REVOKE语句撤销binghe_login用户的USAGE权限。
mysql> REVOKE USAGE ON *.* FROM 'binghe_login'@'localhost';Query OK, 0 rows affected (0.00 sec)SQL语句执行成功,查看binghe_login的权限。
mysql> SHOW GRANTS FOR 'binghe_login'@'localhost';+--------------------------------------------------+| Grants for [email protected] |+--------------------------------------------------+| GRANT USAGE ON *.* TO 'binghe_login'@'localhost' |+--------------------------------------------------+1 row in set (0.00 sec)binghe_login用户仍然具有USAGE权限,说明REVOKE语句不能撤销用户的USAGE权限。
30.6.2 通过操作数据表撤销用户权限
本节以撤销binghe_test用户的权限为例进行简单说明。例如,通过修改mysql.user数据表的权限字段的值来撤销binghe_test用户对所有数据表的修改权限。
mysql> UPDATE mysql.user SET update_priv = 'N' WHERE user = 'binghe_test' AND host = 'localhost';Query OK, 1 row affected (0.00 sec)Rows matched: 1 Changed: 1 Warnings: 0SQL语句执行成功,查看binghe_test用户的权限。
mysql> FLUSH PRIVILEGES;Query OK, 0 rows affected (0.00 sec)mysql> SHOW GRANTS FOR 'binghe_test'@'localhost';+----------------------------------------------------------+| Grants for [email protected] |+----------------------------------------------------------+| GRANT SELECT, INSERT ON *.* TO 'binghe_test'@'localhost' |+----------------------------------------------------------+1 row in set (0.00 sec)可以看到,已经撤销了binghe_test用户对所有数据表的修改权限。
通过操作数据表来修改用户权限时,需要注意如下事项:
·如果是修改用户对所有数据库中所有数据表的权限,则可以操作mysql.user数据表;
·如果是修改用户对某个数据库下的所有数据表的权限,则可以操作mysql.db数据表;
·如果是修改用户对某个数据库下的特定数据表的权限,则可以操作mysql.tables_priv数据表;
·如果是修改用户对某个数据库下的某个数据表的特定字段的权限,则可以操作mysql.columns_priv数据表.
边栏推荐
- EasyCVR平台关闭录像为何还会有TS切片文件生成?
- access control
- A new UI testing method: visual perception test
- IE11 下载doc pdf等文件的方法
- ES6 -- Deconstruction assignment
- Unity fairygui play video (Lua)
- antdv: Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key
- 【阿里安全 × ICDM 2022】20万奖金池!大规模电商图上的风险商品检测赛火热报名中!...
- Linked list~~~
- In 2019, China's smart machine Market: Huawei won nearly 4 components, firmly ranking first in China
猜你喜欢

Mlx90640 infrared thermal imager temperature sensor module development notes (VII)

Scrollintoview realizes simple anchor location (example: select city list)

学习Blender必备的12款动画插件,来了解一下

Lennix Lai, OKx financial market director: Web3 is a revolution

盘点下互联网大厂的实习薪资:有了它,你也可以进厂

C语言--数组

分享Redshift渲染器的去噪方法技巧,一定要看看

多点双向重发布及路由策略的简单应用

Technology sharing | how to do Assertion Verification in interface automated testing?

【效率】弃用 Notepad++,这款开源替代品更牛逼!
随机推荐
做测试, 就得去大厂,内部披露BAT大厂招聘“潜规则”
A recently summarized universal violent cracking method
Understand the wonderful use of dowanward API, and easily grasp kubernetes environment variables
【分层强化学习】HAC论文及代码
Add joint control to gltf model
How to optimize the open source community experience through developer metrics
slf4j中如何进行log4j配置呢?
软件测试面试题:字符串 “axbyczdj“,如果得到结果“abcd
Redis queue, RDB learning
图解LeetCode——剑指 Offer II 115. 重建序列(难度:中等)
Express: search product API by keyword
Knowledge dry goods: basic storage service novice Experience Camp
学习Blender必备的12款动画插件,来了解一下
Jetpack Compose 性能优化指南——编译指标
[rctf2015]easysql-1 | SQL injection
Assignment 1 - Hello World ! - Simple thread Creation
PyQt5快速开发与实战 4.3 QLabel and 4.4 文本框类控件
antdv: Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key
(manual) [sqli labs38, 39] stack injection, error echo, character / number type
Introduction to zepto