Skip to content

Instantly share code, notes, and snippets.

@gh640
Last active December 4, 2021 08:20
Show Gist options
  • Select an option

  • Save gh640/26eba264c2e8aaa11c2691ed534327a7 to your computer and use it in GitHub Desktop.

Select an option

Save gh640/26eba264c2e8aaa11c2691ed534327a7 to your computer and use it in GitHub Desktop.
List up large database tables in MySQL / MariaDB
-- All databases.
SELECT
table_schema AS `Database`,
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS `Size in MB`
FROM information_schema.tables
GROUP BY `Database`
ORDER BY `Size in MB` DESC;
-- See: https://stackoverflow.com/questions/9620198/how-to-get-the-sizes-of-the-tables-of-a-mysql-database
-- Largest 10 tables.
SELECT
table_schema AS `Database`,
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) AS `Size in MB`
FROM information_schema.TABLES
ORDER BY `Size in MB` DESC
LIMIT 10;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment