show grants for 显示用户权限

本文将介绍 mysql 的 show grants for 命令,用来显示用户权限。

mysql 中可以使用 show grants for 命令可以显示指定用户拥有的权限。语法如下:

SHOW GRANTS
    [FOR user_or_role
        [USING role [, role] ...]]

user_or_role: {
    user (see Section 6.2.4, “Specifying Account Names”)
  | role (see Section 6.2.5, “Specifying Role Names”.
}

实例

(1)查看 root 用户的权限信息,如下:

mysql> show grants for 'root'@'%';
+-------------------------------------------------------+
| Grants for root@%                                     |
+-------------------------------------------------------+
| GRANT USAGE ON *.* TO 'root'@'%'                      |
| GRANT SELECT, INSERT, UPDATE ON `db1`.* TO 'root'@'%' |
+-------------------------------------------------------+
2 rows in set (0.05 sec)

(2)使用 \G 通过格式的方式查看 root 用户的权限,如下:

mysql> show grants for 'root'@'%' \G
*************************** 1. row ***************************
Grants for root@%: GRANT USAGE ON *.* TO 'root'@'%'
*************************** 2. row ***************************
Grants for root@%: GRANT SELECT, INSERT, UPDATE ON `db1`.* TO 'root'@'%'
2 rows in set (0.00 sec)

如果用户没有通过 grants 命令授权,使用 show grants for 命令将显示下面信息:

mysql> show grants for 'root'@'%';
1141 - There is no such grant defined for user 'root' on host '%'
学习有两忌,自高和自狭。 —— 书摘
0 不喜欢
说说我的看法 -
全部评论(
没有评论
关于
本网站专注于 Java、数据库(MySQL、Oracle)、Linux、软件架构及大数据等多领域技术知识分享。涵盖丰富的原创与精选技术文章,助力技术传播与交流。无论是技术新手渴望入门,还是资深开发者寻求进阶,这里都能为您提供深度见解与实用经验,让复杂编码变得轻松易懂,携手共赴技术提升新高度。如有侵权,请来信告知:hxstrive@outlook.com
其他应用
公众号