Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@Kevinlearynet Kevinlearynet commented Jul 6, 2017

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