Created
September 30, 2015 08:32
-
-
Save karmiphuc/3a0559fdc102a4a25a7f to your computer and use it in GitHub Desktop.
Drop inactive tables (MyISAM engine) which haven't been accessed for 2 months
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
; Drop query | |
SET group_concat_max_len = 1024 * 1024 * 10; | |
SELECT CONCAT('DROP TABLE ',GROUP_CONCAT(CONCAT(table_schema,'.',table_name)),';') INTO @dropcmd FROM information_schema.tables | |
WHERE table_schema = 'test' | |
AND table_name LIKE '%temp\_data%' | |
AND DATE_ADD(update_time, INTERVAL +2 month) < CURDATE() | |
ORDER BY update_time DESC; | |
PREPARE str FROM @dropcmd; EXECUTE str; DEALLOCATE PREPARE str; | |
; Example Query | |
SELECT table_schema, | |
table_name, | |
update_time as LastAccessed | |
FROM information_schema.tables | |
WHERE table_schema = 'test' | |
AND table_name LIKE '%temp\_data%' | |
AND DATE_ADD(update_time, INTERVAL +2 month) < CURDATE() | |
ORDER BY update_time DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment