Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
306 views
in Technique[技术] by (71.8m points)

mysql - 如何获取MySQL数据库表的大小?(How to get the sizes of the tables of a MySQL database?)

I can run this query to get the sizes of all tables in a MySQL database:

(我可以运行此查询来获取MySQL数据库中所有表的大小:)

show table status from myDatabaseName;

I would like some help in understanding the results.

(我想在理解结果方面提供一些帮助。)

I am looking for tables with the largest sizes.

(我正在寻找最大尺寸的桌子。)

Which column should I look at?

(我应该看哪一栏?)

  ask by JPashs translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...