Skip to content

Instantly share code, notes, and snippets.

@ivanrosolen
Created December 18, 2018 20:36
Show Gist options
  • Save ivanrosolen/5e3054982034f3ffcec7cf8787dce598 to your computer and use it in GitHub Desktop.
Save ivanrosolen/5e3054982034f3ffcec7cf8787dce598 to your computer and use it in GitHub Desktop.
How to get the size of mysql tables?
-- All Databases and Tables
SELECT
table_schema AS `Database`,
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM
information_schema.TABLES
ORDER BY
(data_length + index_length)
DESC;
-- All Tables from a Database
SELECT
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM
information_schema.TABLES
WHERE
table_schema = 'DATABASE_NAME'
ORDER BY
(data_length + index_length)
DESC;
-- A table from a Database
SELECT
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024),2) `Size in MB`
FROM
information_schema.TABLES
WHERE
table_schema = 'DATABASE_NAME'
AND table_name = 'TABLE_NAME';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment