如何获取MySQL数据库表的大小?

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

show table status from myDatabaseName;

我希望在理解结果方面有所帮助。 我正在寻找最大尺寸的桌子。

我应该看哪一列?


您可以使用此查询来显示表的大小(尽管您需要先替换变量):

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";

或者这个查询来列出每个数据库中每个表的大小,首先是最大的:

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;

SELECT TABLE_NAME AS "Table Name", 
table_rows AS "Quant of Rows", ROUND( (
data_length + index_length
) /1024, 2 ) AS "Total Size Kb"
FROM information_schema.TABLES
WHERE information_schema.TABLES.table_schema = 'YOUR SCHEMA NAME/DATABASE NAME HERE'
LIMIT 0 , 30

您可以从“ information_schema ” - > SCHEMATA表 - >“ SCHEMA_NAME ”列中获取模式名称


额外你可以得到如下的mysql数据库的大小

SELECT table_schema "DB Name", 
Round(Sum(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB" 
FROM   information_schema.tables 
GROUP  BY table_schema; 

结果

DB Name              |      DB Size in MB

mydatabase_wrdp             39.1
information_schema          0.0

你可以在这里获得更多的细节。


SELECT 
    table_name AS "Table",  
    round(((data_length + index_length) / 1024 / 1024), 2) as size   
FROM information_schema.TABLES  
WHERE table_schema = "YOUR_DATABASE_NAME"  
ORDER BY size DESC; 

这种排列的大小(DB大小以MB为单位)。

链接地址: http://www.djcxy.com/p/30517.html

上一篇: How to get the sizes of the tables of a MySQL database?

下一篇: Insert into a MySQL table or update if exists