Skip to content

Instantly share code, notes, and snippets.

@gjaya79
Last active August 29, 2015 14:03
Show Gist options
  • Save gjaya79/79f45cba37371d8b8a67 to your computer and use it in GitHub Desktop.
Save gjaya79/79f45cba37371d8b8a67 to your computer and use it in GitHub Desktop.
MYSQL SPECIAL QUERY
Show the database sizes:
SELECT table_schema "Data Base Name", sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB"
FROM information_schema.TABLES GROUP BY table_schema ;
Show table sizes
SELECT TABLE_NAME "Table Name", (data_length + index_length) / 1024 / 1024 "Table Size in MB", TABLE_ROWS "Number of row(s)"
FROM information_schema.TABLES where TABLE_SCHEMA='';
Delete rows which are 180 days older;
DELETE FROM apihistory
WHERE timestamp < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 180 DAY));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment