Last active
December 23, 2015 05:59
-
-
Save jeffreyroberts/6590635 to your computer and use it in GitHub Desktop.
MySQL - Monitor growth history of all databases and tables hosted on a MySQL Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- SET GLOBAL event_scheduler = ON; | |
-- create table db_growth_history(db_name varchar(64), tbl_name varchar(64), avg_row_length int, row_count bigint, time_stamp datetime); | |
DELIMITER $$ | |
CREATE | |
EVENT `document_db_growth_history` | |
ON SCHEDULE EVERY 1 DAY | |
DO BEGIN | |
-- Grab db name, table name, avg row length, row count, add timestamp = growth_history | |
INSERT INTO db_growth_history(db_name,tbl_name,avg_row_length,row_count,time_stamp) | |
SELECT TABLE_SCHEMA, TABLE_NAME, AVG_ROW_LENGTH, TABLE_ROWS, NOW() FROM `information_schema`.`tables`; | |
-- End Query | |
END $$ | |
DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output Example:
+--------------------+----------------+----------------+-----------+---------------------+
| db_name | tbl_name | avg_row_length | row_count | time_stamp |
+--------------------+----------------+----------------+-----------+---------------------+
| information_schema | CHARACTER_SETS | 384 | NULL | 2013-09-17 02:11:16 |
+--------------------+----------------+----------------+-----------+---------------------+
1 row in set (0.00 sec)