MySQL Query For All Tables Sorted by Size

Allure Web Solutions Code Snippet

This snippet queries your MySQL database for all tables and then returns their sizes sorted from largest to smallest.

Replace DATABASE with the name of your database.

SELECT
  TABLE_NAME AS `Table`,
  ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)`
FROM
  information_schema.TABLES
WHERE
  TABLE_SCHEMA = "DATABASE"
ORDER BY
  (DATA_LENGTH + INDEX_LENGTH)
DESC;

 

Mike Doubintchik

Author Mike Doubintchik

More posts by Mike Doubintchik

Leave a Reply