mysql 占用空間 MySQL檢視表占用空間大小

2021-10-17 23:44:19 字數 3404 閱讀 6958

前言在mysql中有乙個預設的資料表information_schema,information_schema這張資料表儲存了mysql伺服器所有資料庫的資訊。如資料庫名,資料庫的表,表欄的資料型別與訪問許可權等。

再簡單點,這台mysql伺服器上,到底有哪些資料庫、各個資料庫有哪些表,每張表的字段型別是什麼,各個資料庫要什麼許可權才能訪問,等等資訊都儲存在information_schema表裡面,所以請勿刪改此表。

**1,切換資料庫

use information_schema;

2,檢視資料庫使用大小

select concat(round(sum(data_length/1024/1024),2),』mb』) as data from tables wheretable_schema=』db_name』 ;

3,檢視表使用大小

select concat(round(sum(data_length/1024/1024),2),』mb』) as data from tables wheretable_schema=』db_name』 andtable_name=』table_name』;

網上找的乙個,親測可用:

先進去mysql自帶管理庫:information_schema

然後查詢 data_length,index_length

你自己的資料庫名:dbname

你自己的表名:tablename

mysql>use information_schema;

database changed

mysql>select data_length,index_length

->from tables where

->table_schema='dbname'

->andtable_name='tablename';

| data_length | index_length |

|   166379520 |    235782144 |

row in set (0.02 sec)

mysql>select concat(round(sum(data_length/1024/1024),2),'mb') as data_length_mb,

->concat(round(sum(index_length/1024/1024),2),'mb') as index_length_mb

->from tables where

->table_schema='dbname'

->andtable_name='tablename';

| data_length_mb | index_length_mb |

| 158.67mb       | 224.86mb        |

row in set (0.03 sec)

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)) as '索引容量(mb)'

from information_schema.tables

group by table_schema

order by sum(data_length) desc, sum(index_length) desc;

### 2.檢視所有資料庫各表容量大小

```sql

select

table_schema as '資料庫',

table_name as '表名',

table_rows as '記錄數',

truncate(data_length/1024/1024, 2) as '資料容量(mb)',

truncate(index_length/1024/1024, 2) as '索引容量(mb)'

from information_schema.tables

order by data_length desc, index_length desc;

3.檢視指定資料庫容量大小

例:檢視mysql庫容量大小

select

table_schema as '資料庫',

sum(table_rows) as '記錄數',

sum(truncate(data_length/1024/1024, 2)) as '資料容量(mb)',

sum(truncate(index_length/1024/1024, 2)) as '索引容量(mb)'

from information_schema.tables

where table_schema='mysql';

4.檢視指定資料庫各表容量大小

例:檢視mysql庫各表容量大小

select

table_schema as '資料庫',

table_name as '表名',

table_rows as '記錄數',

truncate(data_length/1024/1024, 2) as '資料容量(mb)',

truncate(index_length/1024/1024, 2) as '索引容量(mb)'

from information_schema.tables

where table_schema='mysql'

order by data_length desc, index_length desc;

select concat(round(sum(data_length/1024/1024),2),'mb') as data_length_mb, concat(round(sum(index_length/1024/1024),2),'mb') as index_length_mb

from tables

where table_schema='passport'andtable_name='tb_user_info';

-- 569.98mb 141.98mb

select concat(round(sum(data_length/1024/1024),2),'mb') as data_length_mb, concat(round(sum(index_length/1024/1024),2),'mb') as index_length_mb

from tables

where table_schema='passport_v2'andtable_name='tb_user_info';

--   2128.94mb   285.00mb

點讚 0

資料MySQL占用空間數

資料資訊在information schema資料庫中 統計整個資料庫占用空間數 select concat round sum data length index length 1024 1024 2 m from tables 統計單個資料庫及表占用空間數 select concat round...

mysql 查詢表儲存空間占用

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

檢視mysql占用磁碟空間

查詢所有資料庫占用磁碟空間大小的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 ...