MYSQL 檢視資料占用大小

2022-07-11 17:00:13 字數 1316 閱讀 6764

在mysql中有乙個預設的資料表information_schema,information_schema這張資料表儲存了mysql伺服器所有資料庫的資訊。如資料庫名,資料庫的表,表欄的資料型別與訪問許可權等。再簡單點,這台mysql伺服器上,到底有哪些資料庫、各個資料庫有哪些表,每張表的字段型別是什麼,各個資料庫要什麼許可權才能訪問,等等資訊都儲存在information_schema表裡面。

1、檢視資料庫使用情況

索引大小 + 資料大小 = 總大小

select concat(round(sum(index_length)/(1024

*1024), 2), '

mb') as

'total index size',

concat(

round(sum(data_length)/(1024

*1024), 2), '

mb') as

'total data size',

concat(

round(sum(index_length+data_length)/(1024

*1024), 2), '

mb') as

'total size

'from information_schema.tables where table_schema like

'資料庫名';

檢視表占用

表名、行數、資料大小、索引大小、總大小

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 =

'資料庫名';

MySQL檢視表占用空間大小

select table schemaas 資料庫 sum table rows as 記錄數 sum truncate data length 1024 1024,2 as 資料容量 mb sum truncate index length 1024 1024,2 as 索引容量 mb fromi...

MySQL檢視表占用空間大小

需求 我們在選購伺服器硬碟時,通常需要先估算一下資料量。比如我們現在做的專案,百萬級使用者,然後在現有的資料結構中插入一萬條資料,然後根據相應的需求去計算出實際生產中的資料量。前言 在mysql中有乙個預設的資料表information schema,information schema這張資料表儲...

Mysql 檢視資料庫,表占用磁碟大小

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