Skip to content

Instantly share code, notes, and snippets.

@Kevinlearynet
Last active November 8, 2022 06:49
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Kevinlearynet/10288826 to your computer and use it in GitHub Desktop.
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.
# 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
@Kevinlearynet
Copy link
Author

Be sure to replace %%YOURDATABASE%% with your database table name, or remove the WHERE clause entirely to check every database in your MySQL server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment