MySQL Table Size

In one of my project for reducing the site’s server space, I had to go through the database to find the tables that were consuming much space.

Below is the query that I used,

SELECT TABLE_NAME AS `Table`, ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)` FROM information_schema.TABLES WHERE TABLE_SCHEMA = "{database-name}" ORDER BY (DATA_LENGTH + INDEX_LENGTH) DESC

This will give the table names in first column with their size in MB in the second column.

You can further add conditions to filter specific tables or specific size.

Hope this is helpful.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top