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表中存在的,具體可以通過(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)限的方法總結(jié)的文章就介紹到這了,更多相關(guān)兩種MySQL查詢用戶權(quán)限的方法內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
MySQL錯(cuò)誤“Specified key was too long; max key length is 1000 b
今天在為數(shù)據(jù)庫(kù)中的某兩個(gè)字段設(shè)置unique索引的時(shí)候,出現(xiàn)了Specified key was too long; max key length is 1000 bytes錯(cuò)誤2010-08-08MySQL數(shù)據(jù)庫(kù)事務(wù)隔離級(jí)別介紹(Transaction Isolation Level)
這篇文章主要介紹了MySQL數(shù)據(jù)庫(kù)事務(wù)隔離級(jí)別(Transaction Isolation Level) ,需要的朋友可以參考下2014-05-05詳解MySQL單實(shí)例和多實(shí)例啟動(dòng)腳本
這篇文章主要介紹了MySQL單實(shí)例和多實(shí)例啟動(dòng)腳本,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-08-08MySQL過(guò)濾重復(fù)數(shù)據(jù)的兩種方法示例
數(shù)據(jù)庫(kù)生成環(huán)境中經(jīng)常會(huì)遇到表中有重復(fù)的數(shù)據(jù),或者進(jìn)行關(guān)聯(lián)過(guò)程中產(chǎn)生重復(fù)數(shù)據(jù),下面這篇文章主要給大家介紹了關(guān)于MySQL過(guò)濾重復(fù)數(shù)據(jù)的兩種方法,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-04-04window下mysql 8.0.15 安裝配置方法圖文教程
這篇文章主要為大家詳細(xì)介紹了window下mysql 8.0.15 安裝配置方法圖文教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-02-02MySQL數(shù)據(jù)庫(kù)主從復(fù)制延時(shí)超長(zhǎng)的解決方法
這篇文章主要給大家介紹了關(guān)于MySQL數(shù)據(jù)庫(kù)主從復(fù)制延時(shí)超長(zhǎng)的解決方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用MySQL具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06mysql中如何根據(jù)經(jīng)緯度計(jì)算距離
這篇文章主要給大家介紹了關(guān)于mysql中如何根據(jù)經(jīng)緯度計(jì)算距離的相關(guān)資料,經(jīng)緯度距離計(jì)算方法是一種用來(lái)計(jì)算地球上兩個(gè)點(diǎn)之間距離的方法,它可以在MySQL數(shù)據(jù)庫(kù)中輕松實(shí)現(xiàn),非常適用于需要進(jìn)行地理定位的應(yīng)用程序,需要的朋友可以參考下2023-08-08