Last active
November 8, 2022 06:49
-
-
Save Kevinlearynet/10288826 to your computer and use it in GitHub Desktop.
Find the largest (sized by MB) tables in your MySQL database. Especially useful for diagnosing and fixing a bloated WordPress 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
# Find the largest tables in your MySQL database | |
SELECT | |
table_name as "Table", | |
table_rows as "Rows", | |
data_length as "Length", | |
index_length as "Index", | |
round(((data_length + index_length) / 1024 / 1024),2) as "Size (mb)" | |
FROM information_schema.TABLES | |
WHERE table_schema = "%%YOURDATABASE%%" | |
ORDER BY `Size (mb)` DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Be sure to replace
%%YOURDATABASE%%
with your database table name, or remove theWHERE
clause entirely to check every database in your MySQL server.