這篇文章將為大家詳細(xì)講解有關(guān)MySQL中怎么查詢用戶權(quán)限,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
為沂水等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及沂水網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為成都做網(wǎng)站、成都網(wǎng)站設(shè)計、沂水網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!
全局層級
全局權(quán)限適用于一個給定服務(wù)器中的所有數(shù)據(jù)庫。這些權(quán)限存儲在mysql.user表中。GRANT ALL ON *.*和REVOKE ALL ON *.*只授予和撤銷全局權(quán)限。
數(shù)據(jù)庫層級
數(shù)據(jù)庫權(quán)限適用于一個給定數(shù)據(jù)庫中的所有目標(biāo)。這些權(quán)限存儲在mysql.db和mysql.host表中。GRANT ALL ON db_name.*和REVOKE ALL ON db_name.*只授予和撤銷數(shù)據(jù)庫權(quán)限。
表層級
表權(quán)限適用于一個給定表中的所有列。這些權(quán)限存儲在mysql.tables_priv表中。GRANT ALL ON db_name.tbl_name和REVOKE ALL ON db_name.tbl_name只授予和撤銷表權(quán)限。
列層級
列權(quán)限適用于一個給定表中的單一列。這些權(quán)限存儲在mysql.columns_priv表中。當(dāng)使用REVOKE時,您必須指定與被授權(quán)列相同的列。
子程序?qū)蛹?/strong>
CREATE ROUTINE, ALTER ROUTINE, EXECUTE和GRANT權(quán)限適用于已存儲的子程序。這些權(quán)限可以被授予為全局層級和數(shù)據(jù)庫層級。而且,除了CREATE ROUTINE外,這些權(quán)限可以被授予為子程序?qū)蛹墸⒋鎯υ趍ysql.procs_priv表中。
1:那么我們來創(chuàng)建一個測試賬號test,授予全局層級的權(quán)限。如下所示:
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的權(quán)限。如下所示:
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:那么我們來創(chuàng)建一個測試賬號test,授予數(shù)據(jù)庫層級的權(quán)限。如下所示:
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; --可以看到無任何授權(quán)。 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:那么我們來創(chuàng)建一個測試賬號test,授予表層級的權(quán)限。如下所示:
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:那么我們來創(chuàng)建一個測試賬號test,授予列層級的權(quán)限。如下所示:
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:那么我們來創(chuàng)建一個測試賬號test,授子程序?qū)蛹壍臋?quán)限。如下所示:
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>
關(guān)于mysql中怎么查詢用戶權(quán)限就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。