查看权限(SELECT/SHOW GRANTS FOR)

Exisi 2023-01-25 10:27:41
Categories: Tags:
  • MySQL 中,可以通过 SELECT 语句查询 mysql.user 表中的数据记录来查看相应的用户权限,也可以使用 SHOW GRANTS 语句查询用户的权限

  • 新创建的用户只有登录 MySQL 服务器的权限,没有任何其它权限,不能查询 user

 

 

 

使用 SELECT 语句

SELECT语句用于查询数据表字段数据

语法

SELECT * FROM 数据库名

示例

SELECT * FROM mysql.user;

 

 

 

使用 SHOW GRANTS FOR 语句

SHOW GRANTS FORMySQL中用于查看权限用户所有的权限的语句

语法

SHOW GRANTS FOR '用户名'@'IP地址';

示例

mysql> SHOW GRANTS FOR 'root'@'localhost';

+---------------------------------------------------------------------------------------------+

| Grants for root@localhost                                                                                       |

+---------------------------------------------------------------------------------------------+

| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION  |

| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION               |

+---------------------------------------------------------------------------------------------+

2 rows in set (0.00 sec)

示例

mysql> CREATE USER 'testuser1'@'localhost';

Query OK, 0 rows affected (0.00 sec)

 

mysql> SHOW GRANTS FOR 'testuser1'@'localhost';

+-----------------------------------------------------------+

| Grants for testuser1@localhost                                |

+-----------------------------------------------------------+

| GRANT USAGE ON *.* TO 'testuser1'@'localhost' |

+-----------------------------------------------------------+

1 row in set (0.00 sec)

 

 

来自 <http://c.biancheng.net/view/7498.html>