您好,登錄后才能下訂單哦!
怎么在MySQL中查詢用戶權(quán)限?針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。
介紹兩種查看MySQL用戶權(quán)限的兩種方法
1、 使用MySQL grants命令
mysql> show grants for username@localhost; +---------------------------------------------------------------------+ | Grants for root@localhost | +---------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION | +---------------------------------------------------------------------+
需要注意的是:
● username和ip的組合需要是在mysql.user表中存在的,具體可以通過(guò) select * from mysql.user 命令查看
● ip地址如果是通配符格式需要加引號(hào),例如:show grants for root@'172.%';
2、 使用MySQL select命令
mysql> select * from mysql.user where user='root' and host='localhost' \G; *************************** 1. row *************************** Host: localhost User: root Password: ********************** Select_priv: Y Insert_priv: Y Update_priv: Y Delete_priv: Y Create_priv: Y Drop_priv: Y Reload_priv: Y Shutdown_priv: Y Process_priv: Y File_priv: Y Grant_priv: Y References_priv: Y Index_priv: Y Alter_priv: Y Show_db_priv: Y Super_priv: Y Create_tmp_table_priv: Y Lock_tables_priv: Y Execute_priv: Y Repl_slave_priv: Y Repl_client_priv: Y Create_view_priv: Y Show_view_priv: Y Create_routine_priv: Y Alter_routine_priv: Y Create_user_priv: Y Event_priv: Y Trigger_priv: Y Create_tablespace_priv: Y 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.01 sec)
知識(shí)點(diǎn)擴(kuò)展:
我們來(lái)創(chuàng)建一個(gè)測(cè)試賬號(hào)test,授予表層級(jí)的權(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> <br>
我們來(lái)創(chuàng)建一個(gè)測(cè)試賬號(hào)test,授予列層級(jí)的權(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> <br>
關(guān)于怎么在MySQL中查詢用戶權(quán)限問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開(kāi),可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識(shí)。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。