国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

關于MySQL繞過授予information_schema中對象時報ERROR 1044(4200)錯誤

瀏覽:12日期:2023-10-10 13:02:29

這個問題是微信群中網友關于MySQL權限的討論,有這么一個業務需求(下面是他的原話):

因為MySQL的很多功能都依賴主鍵,我想用zabbix用戶,來監控業務數據庫的所有表,是否都建立了主鍵。

監控的語句是:

FROM information_schema.tables t1 LEFT OUTER JOIN information_schema.table_constraints t2 ON t1.table_schema = t2.table_schema AND t1.table_name = t2.table_name AND t2.constraint_name IN ( ’PRIMARY’ ) WHERE t2.table_name IS NULL AND t1.table_schema NOT IN ( ’information_schema’, ’myawr’, ’mysql’, ’performance_schema’, ’slowlog’, ’sys’, ’test’ ) AND t1.table_type = ’BASE TABLE’

但是我不希望zabbix用戶,能讀取業務庫的數據。一旦不給zabbix用戶讀取業務庫數據的權限,那么information_schema.TABLES 和 information_schema.TABLE_CONSTRAINTS 就不包含業務庫的表信息了,也就統計不出來業務庫的表是否有建主鍵。有沒有什么辦法,即讓zabbix不能讀取業務庫數據,又能監控是否業務庫的表沒有建立主鍵?

首先,我們要知道一個事實:information_schema下的視圖沒法授權給某個用戶。如下所示

mysql> GRANT SELECT ON information_schema.TABLES TO test@’%’;ERROR 1044 (42000): Access denied for user ’root’@’localhost’ to database ’information_schema’

關于這個問題,可以參考mos上這篇文章:Why Setting Privileges on INFORMATION_SCHEMA does not Work (文檔 ID 1941558.1)

APPLIES TO:

MySQL Server - Version 5.6 and later

Information in this document applies to any platform.

GOAL

To determine how MySQL privileges work for INFORMATION_SCHEMA.

SOLUTION

A simple GRANT statement would be something like:

mysql> grant select,execute on information_schema.* to ’dbadm’@’localhost’;

ERROR 1044 (42000): Access denied for user ’root’@’localhost’ to database ’information_schema’

The error indicates that the super user does not have the privileges to change the information_schema access privileges.

Which seems to go against what is normally the case for the root account which has SUPER privileges.

The reason for this error is that the information_schema database is actually a virtual database that is built when the service is started.

It is made up of tables and views designed to keep track of the server meta-data, that is, details of all the tables, procedures etc. in the database server.

So looking specifically at the above command, there is an attempt to add SELECT and EXECUTE privileges to this specialised database.

The SELECT option is not required however, because all users have the ability to read the tables in the information_schema database, so this is redundant.

The EXECUTE option does not make sense, because you are not allowed to create procedures in this special database.

There is also no capability to modify the tables in terms of INSERT, UPDATE, DELETE etc., so privileges are hard coded instead of managed per user.

那么怎么解決這個授權問題呢? 直接授權不行,那么我們只能繞過這個問題,間接實現授權。思路如下:首先創建一個存儲過程(用戶數據庫),此存儲過程找出沒有主鍵的表的數量,然后將其授予test用戶。

DELIMITER //CREATE DEFINER=`root`@`localhost` PROCEDURE `moitor_without_primarykey`()BEGIN SELECT COUNT(*) FROM information_schema.tables t1 LEFT OUTER JOIN information_schema.table_constraints t2 ON t1.table_schema = t2.table_schema AND t1.table_name = t2.table_name AND t2.constraint_name IN ( ’PRIMARY’ ) WHERE t2.table_name IS NULL AND t1.table_schema NOT IN ( ’information_schema’, ’myawr’, ’mysql’, ’performance_schema’, ’slowlog’, ’sys’, ’test’ ) AND t1.table_type = ’BASE TABLE’;END //DELIMITER ; mysql> GRANT EXECUTE ON PROCEDURE moitor_without_primarykey TO ’test’@’%’;Query OK, 0 rows affected (0.02 sec)

此時test就能間接的去查詢information_schema下的對象了。

mysql> select current_user();+----------------+| current_user() |+----------------+| test@% |+----------------+1 row in set (0.00 sec) mysql> call moitor_without_primarykey;+----------+| COUNT(*) |+----------+| 6 |+----------+1 row in set (0.02 sec) Query OK, 0 rows affected (0.02 sec)

查看test用戶的權限。

mysql> show grants for test@’%’;+-------------------------------------------------------------------------------+| Grants for test@% |+-------------------------------------------------------------------------------+| GRANT USAGE ON *.* TO `test`@`%` || GRANT EXECUTE ON PROCEDURE `zabbix`.`moitor_without_primarykey` TO `test`@`%` |+-------------------------------------------------------------------------------+2 rows in set (0.00 sec)

到此這篇關于關于MySQL繞過授予information_schema中對象時報ERROR 1044(4200)錯誤的文章就介紹到這了,更多相關mysql ERROR 1044(4200)內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: MySQL 數據庫
相關文章:
主站蜘蛛池模板: 草草影音| 99国产精品九九视频免费看 | 国产成人精选免费视频 | 波多野结衣一区二区三区在线观看 | 最近中文字幕精彩视频 | 特级做a爰片毛片免费看 | 国产成人久久精品麻豆二区 | 成人中文字幕在线观看 | 亚洲精品成人一区 | 萌白酱在线喷水福利视频 | 奇米四色综合久久天天爱 | 欧美日韩在线第一页 | 9191久久久久视频 | 日韩在线精品 | 欧美一级特黄特色大片 | 成年人午夜影院 | 午夜香港三级a三级三点 | 九九视频在线看精品 | 久久看视频 | 黄网在线观看免费 | 欧美综合自拍亚洲综合 | 狼人总合狼人综合 | 国产一区二区三区不卡免费观看 | 久久99国产一区二区三区 | 国产一有一级毛片视频 | 亚洲欧美一区二区久久 | 免费一级欧美片片线观看 | 一级做a爱 | 男女性高爱潮免费网站 | 色视频在线观看视频 | 尹人香蕉久久99天天拍 | 欧美精品aaa久久久影院 | 久久久久久久久久久久福利 | 美女视频大全视频a免费九 美女视频大全网站免费 | 青草青99久久99九九99九九九 | 日韩亚洲天堂 | 91pao强力打造免费高清 | dy888午夜国产午夜精品 | 最新国产精品自拍 | 成人黄页 | 欧美 亚洲 中文字幕 |