Skip to content

Instantly share code, notes, and snippets.

@mysqlboy
Last active July 13, 2021 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mysqlboy/b7e9a5845c3af47d19eeaee558ec59d9 to your computer and use it in GitHub Desktop.
Save mysqlboy/b7e9a5845c3af47d19eeaee558ec59d9 to your computer and use it in GitHub Desktop.
MySQL table sizes
-- top 10
SELECT
CONCAT(table_schema,'.',table_name) AS `tbl`,
round(((data_length + index_length) / POW(1024,2)), 2) `Size_MB`
FROM
information_schema.TABLES
ORDER BY
(data_length + index_length)
DESC limit 10;
-- specific schema
SET @tableschema = 'apps';
SELECT
CONCAT(table_schema,'.',table_name) AS `tbl`,
round(((data_length + index_length) / POW(1024,2)), 2) `Size_MB`
FROM
information_schema.TABLES
WHERE
table_schema = @tableschema
ORDER BY
(data_length + index_length)
DESC limit 10;
=======
SELECT
CONCAT(table_schema,'.',table_name) AS `tbl`,
round(((data_length + index_length) / POW(1024,2)), 2) `Size_MB`,
table_rows/1000000 as rows_mil
FROM
information_schema.TABLES
WHERE
table_name in (
'_billing_events_old',
)
ORDER BY
(data_length + index_length)
DESC limit 10;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment