Skip to main content

MySQL Query For All Tables Sorted by Size

By October 24, 2018Blog, Database, MySQL, Snippets
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;

 

allure

Author allure

More posts by allure

Leave a Reply

Designed by

best down free | web phu nu so | toc dep 2017