MySql 表空間查詢

2021-08-19 22:15:20 字數 2679 閱讀 2562

show variableslike'datadir'

查所有資料庫占用空間大小

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;

查指定資料庫占用空間大小

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

group by table_name

order by data_length desc;

mysql:檢視的資料庫表空間

/*1.檢視索引  

(1)單位是gb*/   

select

concat(round(

sum(index_length)/(1024*1024*1024), 6), 

' gb'

) as

'total index size'

from

information_schema.tables 

where

table_schema 

like

'database'

;   

/*  

+------------------+ 

| total index

size

|   

+------------------+ 

| 1.70 gb |   

+------------------+

*/  

/*  

(2)單位是mb  

*/  

select

concat(round(

sum(index_length)/(1024*1024), 6), 

' mb'

) as

'total index size'

from

information_schema.tables 

where

table_schema 

like

'database'

;  /*  

其中「database

」為你所要檢視的資料庫  

*/  

/*  

2.檢視表空間  

*/  

select

concat(round(

sum(data_length)/(1024*1024*1024), 6), 

' gb'

) as

'total data size'

from

information_schema.tables 

where

table_schema 

like

'database'

;   

/*  

+-----------------+ 

| total data size

|   

+-----------------+ 

| 3.01 gb |   

+-----------------+

*/  

/*  

3.檢視資料庫中所有表的資訊  

*/  

select

concat(table_schema,

'.',table_name) 

as'table name'

,   

table_rows as

'number of rows'

,   

concat(round(data_length/(1024*1024*1024),6),' g'

) as

'data size'

,   

concat(round(index_length/(1024*1024*1024),6),' g'

) as

'index size'

,   

concat(round((data_length+index_length)/(1024*1024*1024),6),' g'

) as

'total'

from

information_schema.tables   

where

table_schema 

like

'database'

;   

mysql查詢使用空間 查詢MYSQL庫表使用空間

1.檢視所有資料庫各容量大小 select table schema as 資料庫 sum table rows as 記錄數 sum truncate data length 1024 1024,2 as 資料容量 mb sum truncate index length 1024 1024,2 ...

查詢mysql庫空間 查詢MYSQL庫表使用空間

1.檢視所有資料庫各容量大小 select table schema as 資料庫 sum table rows as 記錄數 sum truncate data length 1024 1024,2 as 資料容量 mb sum truncate index length 1024 1024,2 ...

mysql 查詢表儲存空間占用

使用 schema 資料庫 mysql use information schema 字段 說明table schema 資料庫名 table name 表名engine 所使用的儲存引擎 tables rows 記錄數data length 資料大小 index length 索引大小 查詢資料庫...