Last active
May 6, 2025 12:23
-
-
Save vyspiansky/584c4f95cd8706be30aca4730fb3710d to your computer and use it in GitHub Desktop.
Top 10 largest tables in a MySQL database
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
-- Top 10 largest tables in a MySQL database | |
-- MySQL 5.7.29 | |
SELECT | |
table_schema AS `Database`, | |
table_name AS `Table`, | |
ROUND((data_length + index_length) / 1024 / 1024, 2) AS `Size (MB)`, | |
ROUND(data_length / 1024 / 1024, 2) AS `Data Size (MB)`, | |
ROUND(index_length / 1024 / 1024, 2) AS `Index Size (MB)`, | |
table_rows as 'Rows' | |
FROM | |
information_schema.tables | |
WHERE | |
-- table_schema = 'my_database' AND table_type = 'BASE TABLE' | |
-- table_type = 'BASE TABLE' | |
table_schema NOT IN ('mysql', 'information_schema', 'performance_schema', 'sys') | |
ORDER BY | |
(data_length + index_length) DESC | |
LIMIT 10; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment