当前位置:网站首页>用户和权限撤销用户权限
用户和权限撤销用户权限
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数据表.
边栏推荐
- 做测试, 就得去大厂,内部披露BAT大厂招聘“潜规则”
- Linked list~~~
- Understand │ what is cross domain? How to solve cross domain problems?
- Get wechat product details API
- Technology sharing | how to do Assertion Verification in interface automated testing?
- Redis basic understanding, five basic data types
- Built in functions other functions
- Built in function time date function
- IE11 下载doc pdf等文件的方法
- 如何监控NVIDIA Jetson的的运行状态和使用情况
猜你喜欢

Preprocessing and macro definition

IM即时通讯开发如何提升移动网络下图片传输速度和成功率

办公自动化解决方案——DocuWare Cloud 将应用程序和流程迁移到云端的完整的解决方案

Flask-MDict搭建在线Mdict词典服务
![[benefit activity] stack a buff for your code! Click](/img/2d/dabf0ad5d7bd553dada5921abf6c06.png)
[benefit activity] stack a buff for your code! Click "tea" to receive the gift

JS realizes video recording - Take cesium as an example

图解LeetCode——592. 分数加减运算(难度:中等)

Idea: solve the problem of code without prompt

Check the internship salary of Internet companies: with it, you can also enter the factory
![(manual) [sqli labs38, 39] stack injection, error echo, character / number type](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
(manual) [sqli labs38, 39] stack injection, error echo, character / number type
随机推荐
一个程序员的水平能差到什么程度?
Common ways to keep requests idempotent
How to configure log4j in slf4j?
软件测试面试题:已知一个字符串为“hello_world_yoyo”, 如何得到一个队列 [“hello“,“world“,“yoyo“]
PyQt5快速开发与实战 4.7 QSpinBox(计数器) and 4.8 QSlider(滑动条)
MySQL log error log
DP (dynamic programming)
Linked list~~~
2022.07.11
Some contents related to cmsis-rtos
Konka semiconductor's first storage master chip was mass produced and shipped, with the first batch of 100000 chips
Slf4j introduction
浅析即时通讯移动端 IM 开发中登录请求的优化
MediaTek releases Helio g80, a mid-range game phone chip
图解LeetCode——剑指 Offer II 115. 重建序列(难度:中等)
shell
[RCTF2015]EasySQL-1|SQL注入
What are the apps of regular futures trading platforms in 2022, and are they safe?
Check the internship salary of Internet companies: with it, you can also enter the factory
Understand the wonderful use of dowanward API, and easily grasp kubernetes environment variables