香港云主机最佳企业级服务商!

ADSL拨号VPS包含了中国大陆(联通,移动,电信,)

中国香港,国外拨号VPS。

当前位置:云主机 > MYSQL >

电信ADSL拨号VPS
联通ADSL拨号VPS
移动ADSL拨号VPS

mysql语句查询用户权限过程详解


时间:2020-11-03 13:41 作者:admin610456


mysql/' target='_blank'>mysql中,如何查看一个用户被授予了那些权限呢? 授予用户的权限可能分全局层级权限、数据库层级权限、表层级别权限、列层级别权限、子程序层级权限。具体分类如下:

全局层级

全局权限适用于一个给定服务器中的所有数据库。这些权限存储在MySQL.user表中。GRANT ALL ON *.*和REVOKE ALL ON *.*只授予和撤销全局权限。

数据库层级

数据库权限适用于一个给定数据库中的所有目标。这些权限存储在mysql.db和mysql.host表中。GRANT ALL ON db_name.*和REVOKE ALL ON db_name.*只授予和撤销数据库权限。

表层级

表权限适用于一个给定表中的所有列。这些权限存储在mysql.tables_priv表中。GRANT ALL ON db_name.tbl_name和REVOKE ALL ON db_name.tbl_name只授予和撤销表权限。

列层级

列权限适用于一个给定表中的单一列。这些权限存储在mysql.columns_priv表中。当使用REVOKE时,您必须指定与被授权列相同的列。

子程序层级

CREATE ROUTINE, ALTER ROUTINE, EXECUTE和GRANT权限适用于已存储的子程序。这些权限可以被授予为全局层级和数据库层级。而且,除了CREATE ROUTINE外,这些权限可以被授予为子程序层级,并存储在mysql.procs_priv表中。

1:那么我们来创建一个测试账号test,授予全局层级的权限。如下所示:

mysql> grant select,insert on *.* to test@'%' identified by 'test';Query OK, 0 rows affected (0.01 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> 

那么可以用下面两种方式查询授予test的权限。如下所示:

mysql> show grants for test;+--------------------------------------------------------------------------------------------------------------+| Grants for test@% |+--------------------------------------------------------------------------------------------------------------+| GRANT SELECT, INSERT ON *.* TO 'test'@'%' IDENTIFIED BY PASSWORD '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29' |+--------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec)mysql> select * from mysql.user where user='test'\G;*************************** 1. row ***************************Host: %User: testPassword: *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29Select_priv: YInsert_priv: YUpdate_priv: NDelete_priv: NCreate_priv: NDrop_priv: NReload_priv: NShutdown_priv: NProcess_priv: NFile_priv: NGrant_priv: NReferences_priv: NIndex_priv: NAlter_priv: NShow_db_priv: NSuper_priv: NCreate_tmp_table_priv: NLock_tables_priv: NExecute_priv: NRepl_slave_priv: NRepl_client_priv: NCreate_view_priv: NShow_view_priv: NCreate_routine_priv: NAlter_routine_priv: NCreate_user_priv: NEvent_priv: NTrigger_priv: NCreate_tablespace_priv: Nssl_type: ssl_cipher: x509_issuer: x509_subject: max_questions: 0max_updates: 0max_connections: 0max_user_connections: 0plugin: mysql_native_passwordauthentication_string: password_expired: N1 row in set (0.04 sec)ERROR: No query specifiedmysql> 

2:那么我们来创建一个测试账号test,授予数据库层级的权限。如下所示:

mysql> drop user test;Query OK, 0 rows affected (0.00 sec)mysql> grant select,insert,update,delete on MyDB.* to test@'%' identified by 'test';Query OK, 0 rows affected (0.01 sec)mysql> mysql> select * from mysql.user where user='test'\G; --可以看到无任何授权。mysql> select * from mysql.db where user='test'\G;*************************** 1. row ***************************Host: %Db: MyDBUser: testSelect_priv: YInsert_priv: YUpdate_priv: YDelete_priv: YCreate_priv: NDrop_priv: NGrant_priv: NReferences_priv: NIndex_priv: NAlter_priv: NCreate_tmp_table_priv: NLock_tables_priv: NCreate_view_priv: NShow_view_priv: NCreate_routine_priv: NAlter_routine_priv: NExecute_priv: NEvent_priv: NTrigger_priv: N1 row in set (0.04 sec)ERROR: No query specifiedmysql> mysql> show grants for test;+-----------------------------------------------------------------------------------------------------+| Grants for test@% |+-----------------------------------------------------------------------------------------------------+| GRANT USAGE ON *.* TO 'test'@'%' IDENTIFIED BY PASSWORD '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29' || GRANT SELECT, INSERT, UPDATE, DELETE ON `MyDB`.* TO 'test'@'%' |+-----------------------------------------------------------------------------------------------------+2 rows in set (0.00 sec)mysql> 

3:那么我们来创建一个测试账号test,授予表层级的权限。如下所示:

mysql> drop user test;Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> grant all on MyDB.kkk to test@'%' identified by 'test';Query OK, 0 rows affected (0.01 sec)mysql> mysql> show grants for test;+-----------------------------------------------------------------------------------------------------+| Grants for test@% |+-----------------------------------------------------------------------------------------------------+| GRANT USAGE ON *.* TO 'test'@'%' IDENTIFIED BY PASSWORD '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29' || GRANT ALL PRIVILEGES ON `MyDB`.`kkk` TO 'test'@'%' |+-----------------------------------------------------------------------------------------------------+2 rows in set (0.00 sec)mysql> select * from mysql.tables_priv\G;*************************** 1. row ***************************Host: %Db: MyDBUser: testTable_name: kkkGrantor: root@localhostTimestamp: 0000-00-00 00:00:00Table_priv: Select,Insert,Update,Delete,Create,Drop,References,Index,Alter,Create View,Show view,TriggerColumn_priv: 1 row in set (0.01 sec)ERROR: No query specifiedmysql> 

4:那么我们来创建一个测试账号test,授予列层级的权限。如下所示:

mysql> drop user test;Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> grant select (id, col1) on MyDB.TEST1 to test@'%' identified by 'test';Query OK, 0 rows affected (0.01 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> mysql> select * from mysql.columns_priv;+------+------+------+------------+-------------+---------------------+-------------+| Host | Db | User | Table_name | Column_name | Timestamp | Column_priv |+------+------+------+------------+-------------+---------------------+-------------+| % | MyDB | test | TEST1 | id | 0000-00-00 00:00:00 | Select || % | MyDB | test | TEST1 | col1 | 0000-00-00 00:00:00 | Select |+------+------+------+------------+-------------+---------------------+-------------+2 rows in set (0.00 sec)mysql> show grants for test;+-----------------------------------------------------------------------------------------------------+| Grants for test@% |+-----------------------------------------------------------------------------------------------------+| GRANT USAGE ON *.* TO 'test'@'%' IDENTIFIED BY PASSWORD '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29' || GRANT SELECT (id, col1) ON `MyDB`.`TEST1` TO 'test'@'%' |+-----------------------------------------------------------------------------------------------------+2 rows in set (0.00 sec)mysql> 

5:那么我们来创建一个测试账号test,授子程序层级的权限。如下所示:

mysql> DROP PROCEDURE IF EXISTS PRC_TEST;Query OK, 0 rows affected (0.00 sec)mysql> DELIMITER //mysql> CREATE PROCEDURE PRC_TEST()-> BEGIN-> SELECT * FROM kkk;-> END //Query OK, 0 rows affected (0.00 sec)mysql> DELIMITER ;mysql> grant execute on procedure MyDB.PRC_TEST to test@'%' identified by 'test';Query OK, 0 rows affected (0.01 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> mysql> show grants for test;+-----------------------------------------------------------------------------------------------------+| Grants for test@% |+-----------------------------------------------------------------------------------------------------+| GRANT USAGE ON *.* TO 'test'@'%' IDENTIFIED BY PASSWORD '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29' || GRANT EXECUTE ON PROCEDURE `MyDB`.`prc_test` TO 'test'@'%' |+-----------------------------------------------------------------------------------------------------+2 rows in set (0.00 sec)mysql> select * from mysql.procs_priv where User='test';+------+------+------+--------------+--------------+----------------+-----------+---------------------+| Host | Db | User | Routine_name | Routine_type | Grantor | Proc_priv | Timestamp |+------+------+------+--------------+--------------+----------------+-----------+---------------------+| % | MyDB | test | PRC_TEST | PROCEDURE | root@localhost | Execute | 0000-00-00 00:00:00 |+------+------+------+--------------+--------------+----------------+-----------+---------------------+1 row in set (0.00 sec)mysql> 

所以,如果需要查看用户被授予的权限,就需要从这五个层级来查看被授予的权限。从上到下或从小到上,逐一检查各个层级被授予的权限。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

(责任编辑:admin)






帮助中心
会员注册
找回密码
新闻中心
快捷通道
域名登录面板
虚机登录面板
云主机登录面板
关于我们
关于我们
联系我们
联系方式

售前咨询:17830004266(重庆移动)

企业QQ:383546523

《中华人民共和国工业和信息化部》 编号:ICP备00012341号

Copyright © 2002 -2018 香港云主机 版权所有
声明:香港云主机品牌标志、品牌吉祥物均已注册商标,版权所有,窃用必究

云官方微信

在线客服

  • 企业QQ: 点击这里给我发消息
  • 技术支持:383546523

  • 公司总台电话:17830004266(重庆移动)
  • 售前咨询热线:17830004266(重庆移动)