Last active
June 11, 2022 10:35
-
-
Save jeffreyroberts/6590485 to your computer and use it in GitHub Desktop.
MySQL - Monitor table growth rates in terms of row counts
This file contains 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 growth_history(tbl_name varchar(64), row_count bigint, time_stamp datetime); | |
DELIMITER $$ | |
CREATE | |
EVENT `document_growth_history` | |
ON SCHEDULE EVERY 1 DAY | |
DO BEGIN | |
-- Insert row counts for each table in the specified database | |
INSERT INTO growth_history(tbl_name,row_count,time_stamp) | |
SELECT TABLE_NAME, TABLE_ROWS, NOW() FROM `information_schema`.`tables` | |
WHERE `table_schema` = '<database_name>'; | |
-- End Query | |
END $$ | |
DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output Example: