MySQL中查詢表及索引大小的方法

2022-04-06 05:53:35 字數 1153 閱讀 8902

查詢mysql表的大小及索引大小可以通過系統庫information_schema中的tables表來實現。

該錶常用的一些字段:

table_schema:資料庫名

table_name:表名

engine:所使用的儲存引擎

tables_rows:記錄行數

data_length:表大小

index_length:索引大小

1、可以查詢資料庫的資料行數、表空間、索引空間,如下,將[資料庫名]替換成你自己的資料庫名即可。

select table_schema

as '庫名',concat(

round(table_rows/10000, 2), ' 萬行') as '行數',concat(

round(sum(data_length)/(1024*1024*1024), 2), ' gb') as '表空間',concat(

round(sum(index_length)/(1024*1024*1024), 2), ' gb') as '索引空間',concat(

round(sum(data_length+index_length)/(1024*1024*1024),2),' gb') as'總空間'from information_schema.tables where table_schema =[資料庫名];

2、當然也可以不彙總,查詢下各個表的情況進行分析,如下,將[資料庫名]替換成你自己的資料庫名即可。

select table_name

as '表名',concat(

round(table_rows/10000, 2), ' 萬行') as '行數',concat(

round(data_length/(1024*1024*1024), 2), ' gb') as '表空間',concat(

round(index_length/(1024*1024*1024), 2), ' gb') as '索引空間',concat(

round((data_length+index_length)/(1024*1024*1024),2),' gb') as'總空間'from information_schema.tables where table_schema = [資料庫名] order by table_rows desc;

MySQL中查詢表及索引大小的方法

查詢mysql表的大小及索引大小可以通過系統庫information schema中的tables表來實現。該錶常用的一些字段 table schema 資料庫名 table name 表名 engine 所使用的儲存引擎 tables rows 記錄行數 data length 表大小 index...

mysql 表空間及索引大小的檢視

table schema 是資料庫名 mysql select concat table schema,table name as table name concat round table rows 1000000,2 m as number of rows concat round data l...

mysql表空間及索引大小的檢視

如果想知道mysql資料庫中每個表占用的空間 表記錄的行數的話,可以開啟mysql的 information schema 資料庫。在該庫中有乙個 tables 表,這個表主要字段分別是 table schema 資料庫名 table name 表名 engine 所使用的儲存引擎 tables r...