查看MySQL數(shù)據(jù)庫(kù)表容量大小

作為DBA肯定要經(jīng)常了解數(shù)據(jù)庫(kù)的空間剩余大小和表空間使用情況。

使用navicat直接查看,不能直觀(guān)的顯示所有的表記錄數(shù)和空間大小使用情況,一般文本記錄數(shù)多,但是占用空間比較大的還是圖片和文件的。

如何查詢(xún)可以顯示所有的表空間記錄數(shù)和表占用空間大小的排名。可以使用下面的語(yǔ)句:

查看所有數(shù)據(jù)庫(kù)容量大小

select

table_schema as '數(shù)據(jù)庫(kù)',

sum(table_rows) as '記錄數(shù)',

sum(truncate(data_length/1024/1024, 2)) as '數(shù)據(jù)容量(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;

查看所有數(shù)據(jù)庫(kù)各表容量大小

select

table_schema as '數(shù)據(jù)庫(kù)',

table_name as '表名',

table_rows as '記錄數(shù)',

truncate(data_length/1024/1024, 2) as '數(shù)據(jù)容量(MB)',

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

from information_schema.tables

order by data_length desc, index_length desc;

如果你有多個(gè)數(shù)據(jù)庫(kù),想要查指定某個(gè)數(shù)據(jù)庫(kù)的大小,可以使用下面的語(yǔ)句:

查看指定數(shù)據(jù)庫(kù)容量大小

例:查看mydb庫(kù)容量大小

select

table_schema as '數(shù)據(jù)庫(kù)',

sum(table_rows) as '記錄數(shù)',

sum(truncate(data_length/1024/1024, 2)) as '數(shù)據(jù)容量(MB)',

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

from information_schema.tables

where table_schema='mydb';

查看指定數(shù)據(jù)庫(kù)各表容量大小

例:查看mydb庫(kù)各表容量大小

select

table_schema as '數(shù)據(jù)庫(kù)',

table_name as '表名',

table_rows as '記錄數(shù)',

truncate(data_length/1024/1024, 2) as '數(shù)據(jù)容量(MB)',

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

from information_schema.tables

where table_schema='mydb'

order by data_length desc, index_length desc;

________________END______________

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容