37

What would be the query to list all tables in a database order by their size in mysql?

4

3 回答 3

91

Try this...

SELECT TABLE_NAME, table_rows, data_length, index_length, 
round(((data_length + index_length) / 1024 / 1024),2) "Size in MB"
FROM information_schema.TABLES WHERE table_schema = "schema_name"
ORDER BY (data_length + index_length) DESC;

Note: Replace schema_name above with the name of your database

于 2013-01-28T19:51:51.360 回答
4

Run the following query in the mysql client

SELECT table_name AS "Tables", 
round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB" 
FROM information_schema.TABLES 
WHERE table_schema = "$DB_NAME"
ORDER BY (data_length + index_length) DESC;
于 2015-07-20T06:28:38.403 回答
-1

Execute following query in information_schema database:

SELECT table_schema AS "Database name",
SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)" 
FROM information_schema.TABLES 
GROUP BY table_schema 
ORDER BY (SUM(data_length + index_length) / 1024 / 1024) DESC;
于 2019-01-03T08:36:30.857 回答