最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MySQL使用show?effective?grants查看權(quán)限官方解讀

 更新時間:2023年07月26日 10:21:28   作者:GreatSQL社區(qū)  
這篇文章主要為大家介紹了MySQL使用show?effective?grants查看權(quán)限,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

1、問題描述

用戶 show grants 顯示只有連接權(quán)限,但該用戶卻能執(zhí)行 sbtest.*下的所有操作

GreatSQL> \s
...
Server version:  8.0.32-24 GreatSQL, Release 24, Revision 3714067bc8c
...
GreatSQL> show grants;
+---------------------------------------+
| Grants for user1@172.%                |
+---------------------------------------+
| GRANT USAGE ON *.* TO `user1`@`172.%` |
+---------------------------------------+
1 row in set (0.00 sec)
GreatSQL> select * from sbtest.sbtest1 limit 1;
+----+-----+-------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------+
| id | k   | c                                                                                                                       | pad                                                         |
+----+-----+-------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------+
|  1 | 250 | 50739423477-59896895752-91121550334-25071371310-03454727381-25307272676-12883025003-48844794346-97662793974-67443907837 | 10824941535-62754685647-36430831520-45812593797-70371571680 |
+----+-----+-------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------+
1 row in set (0.00 sec)

2、官方文檔

MySQL 官方手冊,有這樣一段話

https://dev.mysql.com/doc/refman/8.0/en/show-grants.html

SHOW GRANTS does not display privileges that are available to the named account but are granted to a different account. For example, if an anonymous account exists, the named account might be able to use its privileges, but SHOW GRANTS does not display them.

Percona Server 官方手冊,有類似一段話

https://docs.percona.com/percona-server/8.0/management/extend...

In Oracle MySQL SHOW GRANTS displays only the privileges granted explicitly to the named account. Other privileges might be available to the account, but they are not displayed. For example, if an anonymous account exists, the named account might be able to use its privileges, but SHOW GRANTS will not display them. Percona Server for MySQL offers the SHOW EFFECTIVE GRANTS command to display all the effectively available privileges to the account, including those granted to a different account.

概括如下:

  • 用戶 A 的 user 與用戶 B 的 user 相同,或者用戶 A 是匿名用戶
  • 用戶 B 的 host 范圍是用戶 A 的 host 范圍的子集

滿足上述兩個條件,此時用戶 B 擁有顯式授予給用戶 A 的權(quán)限,但 SHOW GRANTS 不會顯示這部分權(quán)限。在 Percona Server 可以通過 SHOW EFFECTIVE GRANTS 查看。

3、測試驗證

3.1、同 user 用戶

1)、創(chuàng)建用戶并授權(quán)

# 創(chuàng)建用戶
GreatSQL> CREATE USER grantee@localhost IDENTIFIED BY 'grantee1';
Query OK, 0 rows affected (0.05 sec)
GreatSQL> CREATE USER grantee@'%' IDENTIFIED BY 'grantee2';
Query OK, 0 rows affected (0.01 sec)
# 創(chuàng)建數(shù)據(jù)庫
GreatSQL> CREATE DATABASE IF NOT EXISTS sbtest;
Query OK, 1 row affected, 1 warning (0.00 sec)
GreatSQL> CREATE DATABASE IF NOT EXISTS sbtest1;
Query OK, 1 row affected (0.05 sec)
# 授權(quán)
GreatSQL> GRANT ALL PRIVILEGES ON sbtest.* TO grantee@'%';
Query OK, 0 rows affected (0.02 sec)

2)、查看權(quán)限

GreatSQL> show grants for grantee@localhost;
+---------------------------------------------+
| Grants for grantee@localhost                |
+---------------------------------------------+
| GRANT USAGE ON *.* TO `grantee`@`localhost` |
+---------------------------------------------+
1 row in set (0.01 sec)

權(quán)限列表沒有顯示 grantee@localhost 對 sbtest 庫的權(quán)限,但實際 grantee@localhost 已經(jīng)擁有 sbtest 庫下所有操作權(quán)限

3)、grantee@localhost 登錄,執(zhí)行操作

GreatSQL> show grants;
+---------------------------------------------+
| Grants for grantee@localhost                |
+---------------------------------------------+
| GRANT USAGE ON *.* TO `grantee`@`localhost` |
+---------------------------------------------+
1 row in set (0.00 sec)
GreatSQL> create table sbtest.t1(id int primary key);
Query OK, 0 rows affected (0.04 sec)
GreatSQL> insert into sbtest.t1 select 1;
Query OK, 1 row affected (0.01 sec)
Records: 1  Duplicates: 0  Warnings: 0

4)、使用 SHOW EFFECTIVE GRANTS 查看權(quán)限

GreatSQL> show effective grants;
+-------------------------------------------------------------+
| Effective grants for grantee@localhost                      |
+-------------------------------------------------------------+
| GRANT USAGE ON *.* TO `grantee`@`localhost`                 |
| GRANT ALL PRIVILEGES ON `sbtest`.* TO `grantee`@`localhost` |
+-------------------------------------------------------------+
2 rows in set (0.01 sec)

SHOW EFFECTIVE GRANTS顯示出擁有的同 user 用戶權(quán)限

3.2、匿名用戶

匿名用戶請參考:https://dev.mysql.com/doc/refman/8.0/en/connection-access.html

1)、創(chuàng)建匿名用戶并授權(quán)

# 未指定host,默認(rèn)為%
GreatSQL> CREATE USER '';
Query OK, 0 rows affected (0.04 sec)
GreatSQL> GRANT ALL ON sbtest1.* TO '';
Query OK, 0 rows affected (0.02 sec)

2)、查看權(quán)限

GreatSQL> show grants for grantee@localhost;
+---------------------------------------------+
| Grants for grantee@localhost                |
+---------------------------------------------+
| GRANT USAGE ON *.* TO `grantee`@`localhost` |
+---------------------------------------------+
1 row in set (0.01 sec)

權(quán)限列表沒有顯示 grantee@localhost 對 sbtest1 庫的權(quán)限,但實際 grantee@localhost 已經(jīng)擁有 sbtest1 庫下所有操作權(quán)限

3)、grantee@localhost 登錄,執(zhí)行操作

GreatSQL> select user(), current_user();
+-------------------+-------------------+
| user()            | current_user()    |
+-------------------+-------------------+
| grantee@localhost | grantee@localhost |
+-------------------+-------------------+
1 row in set (0.00 sec)
GreatSQL> show grants;
+---------------------------------------------+
| Grants for grantee@localhost                |
+---------------------------------------------+
| GRANT USAGE ON *.* TO `grantee`@`localhost` |
+---------------------------------------------+
1 row in set (0.00 sec)
GreatSQL> create table sbtest1.t2(id int primary key);
Query OK, 0 rows affected (0.03 sec)
GreatSQL> insert into sbtest1.t2 select 2;
Query OK, 1 row affected (0.01 sec)
Records: 1  Duplicates: 0  Warnings: 0

4)、使用 SHOW EFFECTIVE GRANTS 查看權(quán)限

GreatSQL> show effective grants;
+-------------------------------------------------------------+
| Effective grants for grantee@localhost                      |
+-------------------------------------------------------------+
| GRANT USAGE ON *.* TO `grantee`@`localhost`                 |
| GRANT ALL PRIVILEGES ON `sbtest`.* TO `grantee`@`localhost` |
+-------------------------------------------------------------+
2 rows in set (0.01 sec)

注意:SHOW EFFECTIVE GRANTS沒有顯示出擁有的匿名用戶權(quán)限,sbtest.*是擁有的同 user 用戶權(quán)限

4、建議

1)、使用 SHOW EFFECTIVE GRANTS 代替 SHOW GRANTS(GreatDB、GreatSQL、Percona Server)

GreatSQL> show effective grants for user1@`172.%`;
+-------------------------------------------------------+
| Effective grants for user1@172.%                      |
+-------------------------------------------------------+
| GRANT USAGE ON *.* TO `user1`@`172.%`                 |
| GRANT ALL PRIVILEGES ON `sbtest`.* TO `user1`@`172.%` |
+-------------------------------------------------------+
2 rows in set (0.00 sec)

2)、賬號加固

  • 匿名用戶,禁止匿名用戶登錄
GreatSQL> select user, host from mysql.user where user='';
+------+------+
| user | host |
+------+------+
|      | %    |
+------+------+
1 row in set (0.02 sec)
  • 同 user 不同 host
GreatSQL> select u.user, u.host, p.user priv_user, p.host priv_host from (
    -> select user, host from mysql.db
    -> union
    -> select user, host from mysql.tables_priv
    -> union
    -> select user, host from mysql.columns_priv) p
    -> left join mysql.user u on p.user=u.user 
    -> where p.host<>u.host;
+---------+-----------+-----------+-----------+
| user    | host      | priv_user | priv_host |
+---------+-----------+-----------+-----------+
| user1   | 172.%     | user1     | %         |
| grantee | localhost | grantee   | %         |
+---------+-----------+-----------+-----------+
2 rows in set (0.01 sec)

到各權(quán)限表查看對應(yīng)user信息,核實權(quán)限'錯亂'的原因

GreatSQL> select * from mysql.user where user='user1'\G
*************************** 1. row ***************************
                    Host: 172.%
                    User: user1
             Select_priv: N
             ...
1 row in set (0.05 sec)
GreatSQL> select * from mysql.db where user='user1'\G
*************************** 1. row ***************************
                 Host: %
                   Db: sbtest
                 User: user1
          Select_priv: Y
          ...
1 row in set (0.01 sec)

user 表只有 user1@'172.%',db 表只有 user1@'%',對應(yīng)算兩個用戶。

可能是手動更新過權(quán)限表:例如創(chuàng)建用戶xx@'%',授權(quán)db.*所有權(quán)限,后來更新mysql.user表中的記錄為xx@'172.%'限制登錄來源。

根據(jù)精確匹配原則,user1可以從172.%主機連接數(shù)據(jù)庫,全局權(quán)限為N(mysql.user),db權(quán)限匹配上user1@'%',擁有sbtest庫的所有操作權(quán)限。

Enjoy GreatSQL :)

## 關(guān)于 GreatSQL

GreatSQL是由萬里數(shù)據(jù)庫維護的MySQL分支,專注于提升MGR可靠性及性能,支持InnoDB并行查詢特性,是適用于金融級應(yīng)用的MySQL分支版本。

相關(guān)鏈接:

GreatSQL社區(qū) 

Gitee

GitHub

Bilibili

以上就是MySQL使用show effective grants查看權(quán)限的詳細(xì)內(nèi)容,更多關(guān)于MySQL show effective grants查看權(quán)限的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Mysql常見的驅(qū)動程序使用

    Mysql常見的驅(qū)動程序使用

    MySQL驅(qū)動程序是連接應(yīng)用程序與MySQL數(shù)據(jù)庫的重要組件,本文主要介紹了Mysql常見的驅(qū)動程序使用,文中通過示例代碼介紹的非常詳細(xì),需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2025-03-03
  • mysql求和函數(shù)使用示例

    mysql求和函數(shù)使用示例

    求和函數(shù)在某些有計算的情況下會使用到,在本將為大家介紹下mysql中時如何實現(xiàn)求和的,感興趣的朋友可以參考下,希望對大家有所幫助
    2013-09-09
  • MySQL數(shù)據(jù)庫定時備份的實現(xiàn)方法

    MySQL數(shù)據(jù)庫定時備份的實現(xiàn)方法

    這篇文章主要介紹了MySQL數(shù)據(jù)庫的定時備份的相關(guān)知識,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-04-04
  • 詳解MySQL 查詢語句的執(zhí)行過程

    詳解MySQL 查詢語句的執(zhí)行過程

    這篇文章主要介紹了詳解MySQL 查詢語句的執(zhí)行過程,幫助大家更好的理解和學(xué)習(xí)使用MySQL,感興趣的朋友可以了解下
    2021-03-03
  • MySql實現(xiàn)翻頁查詢功能

    MySql實現(xiàn)翻頁查詢功能

    分頁查詢在網(wǎng)頁中隨處可見,那原理是什么呢?下面簡單介紹一下基于MySql數(shù)據(jù)庫的limit實現(xiàn)方法,感興趣的朋友一起看看吧
    2019-11-11
  • 詳解 Mysql查詢結(jié)果順序按 in() 中ID 的順序排列

    詳解 Mysql查詢結(jié)果順序按 in() 中ID 的順序排列

    這篇文章主要介紹了詳解 Mysql查詢結(jié)果順序按 in() 中ID 的順序排列的相關(guān)資料,希望通過本文能幫助到大家,需要的朋友可以參考下
    2017-09-09
  • 解決Mysql:ERROR?1045?(28000):Access?denied?for?user?‘root‘@‘localhost‘?(using?password:?NO)的方法

    解決Mysql:ERROR?1045?(28000):Access?denied?for?user?‘roo

    最近在我們連接數(shù)據(jù)庫的時候遇到個問題,感覺還挺容易遇到的,所以總結(jié)下,這篇文章主要給大家介紹了關(guān)于解決Mysql:ERROR?1045?(28000):Access?denied?for?user?‘root‘@‘localhost‘?(using?password:?NO)的方法,需要的朋友可以參考下
    2022-06-06
  • 一文詳解MySQL?Join使用原理

    一文詳解MySQL?Join使用原理

    JOIN是一種非常常見的操作,用于將兩個或多個表中的數(shù)據(jù)合并到一個結(jié)果集中。MySQL支持多種JOIN類型,本文通過代碼示例詳細(xì)介紹了Join的使用優(yōu)化,有需要的小伙伴可以參考閱讀
    2023-04-04
  • 深入理解mysql各種鎖

    深入理解mysql各種鎖

    大家好,本篇文章主要講的是深入理解mysql各種鎖,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽
    2021-12-12
  • MySQL 行轉(zhuǎn)列詳情

    MySQL 行轉(zhuǎn)列詳情

    這篇文章主要介紹了MySQL 行轉(zhuǎn)列詳情,MySQL 行轉(zhuǎn)列語句不難,具體的詳細(xì)資料,感興趣的小伙伴可以參考一下
    2022-01-01

最新評論

崇仁县| 黄梅县| 绿春县| 德州市| 邛崃市| 永州市| 安徽省| 额尔古纳市| 溧阳市| 谢通门县| 廉江市| 阳西县| 宁都县| 华池县| 句容市| 图木舒克市| 靖安县| 洱源县| 永嘉县| 田林县| 封开县| 正安县| 夏河县| 安义县| 吉水县| 周口市| 安泽县| 金平| 南陵县| 鹿泉市| 灵丘县| 科技| 鞍山市| 河北省| 临朐县| 呼玛县| 江城| 江孜县| 来宾市| 宕昌县| 洮南市|