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 不喜欢
说说我的看法 -
全部评论(
没有评论
关于
本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明,如果原文没有版权声明,请来信告知:hxstrive@outlook.com
公众号