MySQL 获取数据库/表大小的最小权限

MySQL 获取数据库/表大小的最小权限

我正在使用 centreon_plugins 来监控一些 mysql 数据库。作为最佳实践,我创建了一个专门用于监控的用户,并赋予其尽可能少的权限。

为了进行简单的监控,我通常会创建一个只有 2 个全局权限的监控用户:

mysql> create user 'monitor'@'%' identified by 'monitorpassword';
mysql> grant SHOW DATABASES, REPLICATION CLIENT on *.* to 'monitor'@'%';
mysql> flush privileges;

现在我需要检查数据库大小。要访问数据库大小,我需要用户监视器可以访问 information_schema.tables,但我无法授予它对该表的直接选择权限。

显然我使用的root用户具有GRANT权限。

mysql> show grants;
+---------------------------------------------------------------------+
| Grants for root@localhost                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION        |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql> grant SELECT on information_schema.tables to 'monitor'@'%';
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'information_schema'

拒绝访问是由于 mysql 保留给 information_schema DB 的特定用途;对该 DB 的访问受到授予所有其他 mysql 对象的访问权限的限制。我可以通过授予 SELECT 权限来实现结果来监视用户,但是我不想这样做,因为监视用户没有受到足够的保护(即它的密码以明文形式存储在监视软件中),所以它不能看到应用程序数据。

我尝试了不同数据库和表上的各种权限组合,但都不起作用。(参考。https://dev.mysql.com/doc/refman/5.7/en/grant.html

有人有同样的需求吗?他/她是如何解决的?

为了完整性,监控插件执行的查询是:

show variables like 'innodb_file_per_table'
SELECT table_schema, table_name, engine, data_free, data_length+index_length as data_used, (DATA_FREE / (DATA_LENGTH+INDEX_LENGTH)) as TAUX_FRAG FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND engine IN ('InnoDB', 'MyISAM')

提前致谢。 Flavio

相关内容