MySQL資料庫及表空間占用資訊統計

2021-10-05 19:12:44 字數 1472 閱讀 8376

這裡用到乙個表, information_schema.tables;對應主要字段含義如下:

table_schema : 資料庫名

table_name:表名

engine:所使用的儲存引擎

tables_rows:記錄數

data_length:資料大小

index_length:索引大小

1.查詢資料庫,表,行數統計記錄

select table_schema,table_name,table_rows from information_schema.tables order by table_rows desc;
2.查詢所有資料庫占用磁碟空間大小

select table_schema, concat(truncate(sum(data_length)/1024/1024,2),' mb') as data_size,

concat(truncate(sum(index_length)/1024/1024,2),' mb') as index_size

from information_schema.tables

group by table_schema

order by data_length desc;

3.查詢單個庫中所有表磁碟占用大小

select table_name, concat(truncate(data_length/1024/1024,2),' mb') as data_size,

concat(truncate(index_length/1024/1024,2),' mb') as index_size

from information_schema.tables where table_schema = '資料庫名'

group by table_name

order by data_length desc;

4.檢視單個庫的使用情況

select concat(table_schema,'.',table_name) as 'table name',

concat(round(table_rows/1000000,4),'m') as 'number of rows',

concat(round(data_length/(1024*1024*1024),4),'g') as 'data size',

concat(round(index_length/(1024*1024*1024),4),'g') as 'index size',

concat(round((data_length+index_length)/(1024*1024*1024),4),'g') as 'total'

from information_schema.tables

where table_schema like '資料庫名';

Mysql資料庫及表空間占用資訊統計

1 mysql中檢視各表的大小 這裡用到乙個表,information schema.tables 對應主要字段含義如下 able schema 資料庫名 table name 表名 engine 所使用的儲存引擎 tables rows 記錄數 data length 資料大小 index len...

Mysql資料庫及表空間占用資訊統計

1 mysql中檢視各表的大小 這裡用到乙個表,information schema.tables 對應主要字段含義如下 able schema 資料庫名 table name 表名 engine 所使用的儲存引擎 tables rows 記錄數 data length 資料大小 index len...

mysql檢視資料庫和表的占用空間大小

目錄use 資料庫名 select sum data length sum index length from information schema.tables where table schema 資料庫名 得到的結果是以位元組為單位,除1024為k,除1048576為m。select tabl...