Skip to content

Instantly share code, notes, and snippets.

@twfahey1
Last active December 17, 2019 18:41
Show Gist options
  • Save twfahey1/87f4de8273f99a1c3357091cbbaa0f9d to your computer and use it in GitHub Desktop.
Save twfahey1/87f4de8273f99a1c3357091cbbaa0f9d to your computer and use it in GitHub Desktop.
Check table size in mb
In this example using the bookstore database, 
we’re combining the DATA_LENGTH and INDEX_LENGTH as bytes, 
then dividing it by 1024 twice to convert into kilobytes and then megabytes.
SELECT
TABLE_NAME AS `Table`,
ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)`
FROM
information_schema.TABLES
WHERE
TABLE_SCHEMA = "bookstore"
ORDER BY
(DATA_LENGTH + INDEX_LENGTH)
DESC;
SELECT
TABLE_NAME AS `Table`,
ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)`
FROM
information_schema.TABLES
ORDER BY
(DATA_LENGTH + INDEX_LENGTH)
DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment