MySQL查詢用戶權(quán)限的方法總結(jié)
介紹兩種查看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表中存在的,具體可以通過 select * from mysql.user 命令查看
● ip地址如果是通配符格式需要加引號,例如:show grants for root@’172.%’;
2、 使用MySQL select命令
mysql> select * from mysql.user where user=’root’ and host=’localhost’ G;*************************** 1. row ***************************Host: localhostUser: rootPassword: **********************Select_priv: YInsert_priv: YUpdate_priv: YDelete_priv: YCreate_priv: YDrop_priv: YReload_priv: YShutdown_priv: YProcess_priv: YFile_priv: YGrant_priv: YReferences_priv: YIndex_priv: YAlter_priv: YShow_db_priv: YSuper_priv: YCreate_tmp_table_priv: YLock_tables_priv: YExecute_priv: YRepl_slave_priv: YRepl_client_priv: YCreate_view_priv: YShow_view_priv: YCreate_routine_priv: YAlter_routine_priv: YCreate_user_priv: YEvent_priv: YTrigger_priv: YCreate_tablespace_priv: Yssl_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.01 sec)
知識點(diǎn)擴(kuò)展:
我們來創(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_privG;*************************** 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> <br>
我們來創(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> <br>
到此這篇關(guān)于MySQL查詢用戶權(quán)限的方法總結(jié)的文章就介紹到這了,更多相關(guān)兩種MySQL查詢用戶權(quán)限的方法內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. mysql的like模式2. oracle觸發(fā)器介紹3. 通過Backup Exec實(shí)施Oracle來災(zāi)難恢復(fù)4. ACCESS轉(zhuǎn)SQL數(shù)據(jù)庫相關(guān)的幾個技能5. Delphi中的Access技巧集6. 詳解Mysql日期格式并聚合統(tǒng)計(jì)示例7. MySQL基本調(diào)度策略淺析8. 快速刪除ORACLE重復(fù)記錄9. 啟動MYSQL出錯 Manager of pid-file quit without updating file.10. SqlServer服務(wù)中利用觸發(fā)器對指定賬戶進(jìn)行登錄ip限制提升安全性操作
