濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > 關(guān)于MySQL繞過(guò)授予information_schema中對(duì)象時(shí)報(bào)ERROR 1044(4200)錯(cuò)誤

關(guān)于MySQL繞過(guò)授予information_schema中對(duì)象時(shí)報(bào)ERROR 1044(4200)錯(cuò)誤

熱門標(biāo)簽:南通自動(dòng)外呼系統(tǒng)軟件 日照旅游地圖標(biāo)注 信陽(yáng)穩(wěn)定外呼系統(tǒng)運(yùn)營(yíng)商 百度地圖圖標(biāo)標(biāo)注中心 申請(qǐng)外呼電話線路 廣東人工電話機(jī)器人 芒果電話機(jī)器人自動(dòng)化 石家莊電商外呼系統(tǒng) 湖南人工外呼系統(tǒng)多少錢

這個(gè)問(wèn)題是微信群中網(wǎng)友關(guān)于MySQL權(quán)限的討論,有這么一個(gè)業(yè)務(wù)需求(下面是他的原話):

因?yàn)镸ySQL的很多功能都依賴主鍵,我想用zabbix用戶,來(lái)監(jiān)控業(yè)務(wù)數(shù)據(jù)庫(kù)的所有表,是否都建立了主鍵。

監(jiān)控的語(yǔ)句是:

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用戶,能讀取業(yè)務(wù)庫(kù)的數(shù)據(jù)。一旦不給zabbix用戶讀取業(yè)務(wù)庫(kù)數(shù)據(jù)的權(quán)限,那么information_schema.TABLES 和 information_schema.TABLE_CONSTRAINTS 就不包含業(yè)務(wù)庫(kù)的表信息了,也就統(tǒng)計(jì)不出來(lái)業(yè)務(wù)庫(kù)的表是否有建主鍵。有沒有什么辦法,即讓zabbix不能讀取業(yè)務(wù)庫(kù)數(shù)據(jù),又能監(jiān)控是否業(yè)務(wù)庫(kù)的表沒有建立主鍵?

首先,我們要知道一個(gè)事實(shí):information_schema下的視圖沒法授權(quán)給某個(gè)用戶。如下所示

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

關(guān)于這個(gè)問(wèn)題,可以參考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.

那么怎么解決這個(gè)授權(quán)問(wèn)題呢? 直接授權(quán)不行,那么我們只能繞過(guò)這個(gè)問(wèn)題,間接實(shí)現(xiàn)授權(quán)。思路如下:首先創(chuàng)建一個(gè)存儲(chǔ)過(guò)程(用戶數(shù)據(jù)庫(kù)),此存儲(chǔ)過(guò)程找出沒有主鍵的表的數(shù)量,然后將其授予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)

此時(shí)test就能間接的去查詢information_schema下的對(duì)象了。

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用戶的權(quán)限。

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)

到此這篇關(guān)于關(guān)于MySQL繞過(guò)授予information_schema中對(duì)象時(shí)報(bào)ERROR 1044(4200)錯(cuò)誤的文章就介紹到這了,更多相關(guān)mysql ERROR 1044(4200)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • mysql數(shù)據(jù)庫(kù)中的information_schema和mysql可以刪除嗎?
  • 解析MySQL的information_schema數(shù)據(jù)庫(kù)
  • MySQL之information_schema數(shù)據(jù)庫(kù)詳細(xì)講解

標(biāo)簽:阿里 牡丹江 公主嶺 沈陽(yáng) 合肥 惠州 呼和浩特 天津

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《關(guān)于MySQL繞過(guò)授予information_schema中對(duì)象時(shí)報(bào)ERROR 1044(4200)錯(cuò)誤》,本文關(guān)鍵詞  關(guān)于,MySQL,繞過(guò),授予,information,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《關(guān)于MySQL繞過(guò)授予information_schema中對(duì)象時(shí)報(bào)ERROR 1044(4200)錯(cuò)誤》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于關(guān)于MySQL繞過(guò)授予information_schema中對(duì)象時(shí)報(bào)ERROR 1044(4200)錯(cuò)誤的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    广宁县| 扎兰屯市| 通渭县| 南陵县| 泰安市| 正阳县| 平和县| 浦江县| 丰镇市| 文水县| 湄潭县| 崇明县| 揭西县| 玉环县| 虞城县| 英超| 南京市| 咸宁市| 潜江市| 英德市| 景泰县| 德令哈市| 孝义市| 泗水县| 蒙阴县| 蓝山县| 和田市| 兴安盟| 北川| 图木舒克市| 新田县| 安徽省| 彰化市| 遵义市| 雷波县| 庐江县| 治多县| 牡丹江市| 离岛区| 孙吴县| 政和县|