Skip to content

Instantly share code, notes, and snippets.

@danishsatkut
Last active August 13, 2022 08:48
Show Gist options
  • Save danishsatkut/596f3837deb07131884813a1a3e78b98 to your computer and use it in GitHub Desktop.
Save danishsatkut/596f3837deb07131884813a1a3e78b98 to your computer and use it in GitHub Desktop.
Get database/tables size
SELECT *
FROM (SELECT table_schema AS `DB Name`,
ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) AS `DB Size in MB`
FROM information_schema.tables
GROUP BY `DB Name`) AS tmp_table
ORDER BY `DB Size in MB` DESC;
SELECT
TABLE_NAME AS `Table Name`,
ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size ( in MB)`
FROM
information_schema.TABLES
WHERE
TABLE_SCHEMA = "<db_name>"
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