統(tǒng)計mysql數(shù)據(jù)庫占用磁盤空間大小和行數(shù)實例
更新時間:2026年05月09日 17:17:03 作者:左邊有只汪
本文介紹了如何查看MySQL數(shù)據(jù)庫中每個表的占用磁盤空間大小和行數(shù),通過執(zhí)行特定的SQL查詢語句,可以實現(xiàn)對數(shù)據(jù)庫表的大小和行數(shù)的統(tǒng)計
統(tǒng)計mysql數(shù)據(jù)庫占用磁盤空間大小和行數(shù)
1、查看占用磁盤空間大小
select sum(t1.data_size ) as data_sum_size, sum(t1.index_size) as index_sum_size from( select TABLE_NAME, table_schema, truncate(data_length/1024/1024,2) as data_size, -- 查看數(shù)據(jù)占用大小單位為MB truncate(index_length/1024/1024,2) as index_size -- 查看索引占用大小 單位為MB from information_schema.tables where TABLE_SCHEMA = '數(shù)據(jù)庫名' order by data_length desc) t1;
如果想查看該數(shù)據(jù)庫中每個表占用大小的話
select TABLE_NAME, table_schema, truncate(data_length/1024/1024,2) as data_size, -- 查看數(shù)據(jù)占用大小單位為MB truncate(index_length/1024/1024,2) as index_size -- 查看索引占用大小 單位為MB from information_schema.tables where TABLE_SCHEMA = '數(shù)據(jù)庫名' order by data_length desc
2、查看數(shù)據(jù)庫行數(shù)統(tǒng)計
select sum(t1.table_rows) as table_sum from ( select table_name,table_rows from information_schema.tables where TABLE_SCHEMA = '數(shù)據(jù)庫名' order by table_rows desc) t1;
如果要查看數(shù)據(jù)庫中每個表的行數(shù)的話
select table_name,table_rows from information_schema.tables where TABLE_SCHEMA = '數(shù)據(jù)庫名' order by table_rows des
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
mysql實現(xiàn)多表關(guān)聯(lián)統(tǒng)計(子查詢統(tǒng)計)示例
這篇文章主要介紹了mysql實現(xiàn)多表關(guān)聯(lián)統(tǒng)計(子查詢統(tǒng)計),結(jié)合具體案例形式分析了mysql多表關(guān)聯(lián)統(tǒng)計的原理、實現(xiàn)方法及相關(guān)操作注意事項,需要的朋友可以參考下2019-10-10
MySQL數(shù)據(jù)庫的約束與設(shè)計解讀
文章介紹了數(shù)據(jù)庫的約束類型,包括非空約束、默認(rèn)約束、唯一約束、主鍵約束、外鍵約束和check約束,并介紹了數(shù)據(jù)庫設(shè)計的三大范式:第一范式、第二范式和第三范式,還介紹了如何根據(jù)業(yè)務(wù)需求進(jìn)行數(shù)據(jù)庫設(shè)計和創(chuàng)建實體-關(guān)系圖2026-01-01

