Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sanabria/32f633c5b1c5027020b4e98f5150b6c5 to your computer and use it in GitHub Desktop.
Save Sanabria/32f633c5b1c5027020b4e98f5150b6c5 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.
# 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