您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關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: test Password: *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29 Select_priv: Y Insert_priv: Y Update_priv: N Delete_priv: N Create_priv: N Drop_priv: N Reload_priv: N Shutdown_priv: N Process_priv: N File_priv: N Grant_priv: N References_priv: N Index_priv: N Alter_priv: N Show_db_priv: N Super_priv: N Create_tmp_table_priv: N Lock_tables_priv: N Execute_priv: N Repl_slave_priv: N Repl_client_priv: N Create_view_priv: N Show_view_priv: N Create_routine_priv: N Alter_routine_priv: N Create_user_priv: N Event_priv: N Trigger_priv: N Create_tablespace_priv: N ssl_type: ssl_cipher: x509_issuer: x509_subject: max_questions: 0 max_updates: 0 max_connections: 0 max_user_connections: 0 plugin: mysql_native_password authentication_string: password_expired: N 1 row in set (0.04 sec) ERROR: No query specified mysql>
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: MyDB User: test Select_priv: Y Insert_priv: Y Update_priv: Y Delete_priv: Y Create_priv: N Drop_priv: N Grant_priv: N References_priv: N Index_priv: N Alter_priv: N Create_tmp_table_priv: N Lock_tables_priv: N Create_view_priv: N Show_view_priv: N Create_routine_priv: N Alter_routine_priv: N Execute_priv: N Event_priv: N Trigger_priv: N 1 row in set (0.04 sec) ERROR: No query specified mysql> 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: MyDB User: test Table_name: kkk Grantor: root@localhost Timestamp: 0000-00-00 00:00:00 Table_priv: Select,Insert,Update,Delete,Create,Drop,References,Index,Alter,Create View,Show view,Trigger Column_priv: 1 row in set (0.01 sec) ERROR: No query specified mysql>
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>
關于mysql中怎么查詢用戶權限就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。