如何获取MySQL数据库表的大小?
2021-11-20 00:00:00
mysql
我可以运行这个查询来获取 MySQL 数据库中所有表的大小:
I can run this query to get the sizes of all tables in a MySQL database:
show table status from myDatabaseName;
我需要一些帮助来理解结果.我正在寻找最大尺寸的桌子.
I would like some help in understanding the results. I am looking for tables with the largest sizes.
我应该看哪一栏?
推荐答案
您可以使用此查询来显示表的大小(尽管您需要先替换变量):
You can use this query to show the size of a table (although you need to substitute the variables first):
SELECT
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
WHERE table_schema = "$DB_NAME"
AND table_name = "$TABLE_NAME";
或者这个查询列出每个数据库中每个表的大小,最大的在前:
or this query to list the size of every table in every database, largest first:
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;
相关文章