Mysql 列出表和大小 - 按大小排序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14569940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:19:56 来源:igfitidea点击:
Mysql list tables and sizes - order by size
提问by Marty Wallace
What would be the query to list all tables in a database order by their size in mysql?
在 mysql 中按大小按数据库顺序列出所有表的查询是什么?
回答by MG_Bautista
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;
Greetings.
你好。
回答by minhas23
Run the following query in the mysql client
在 mysql 客户端运行以下查询
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;
回答by David Motilla
Execute following query in information_schema database:
在 information_schema 数据库中执行以下查询:
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;