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

2021-09-02 17:24:33 字數 1406 閱讀 6286

1、mysql中檢視各表的大小

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

able_schema : 資料庫名

table_name:表名

engine:所使用的儲存引擎

tables_rows:記錄數

data_length:資料大小

index_length:索引大小

按記錄資料統計:

select table_schema,table_name,table_rows from tables order by table_rows desc;

2、查詢所有資料庫占用磁碟空間大小的sql語句

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、查詢單個庫中所有表磁碟占用大小的sql語句

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 = 'sor'

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 'src';

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

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

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

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

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

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