mysql 快捷查询数据库各表占用空间,mysql查看索引占用空间,mysql查看数据占用空间
生活随笔
收集整理的這篇文章主要介紹了
mysql 快捷查询数据库各表占用空间,mysql查看索引占用空间,mysql查看数据占用空间
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
先貼一張圖!
第一步,“很重要”
在mysql中,有一個創(chuàng)建之初自帶的庫information_schema,這個庫中包含著數(shù)據(jù)庫相關(guān)信息,查詢數(shù)據(jù)占用空間就是使用該庫,所以首先進入這個庫
-- 首先進入mysql系統(tǒng)庫
use information_schema;
第二步:查詢
使用 sum(DATA_LENGTH/1024/1024)統(tǒng)計占用MB大小,分為兩塊,一個是DATA_LENGTH—數(shù)據(jù) 、INDEX_LENGTH—索引。
如下:
-- 查詢數(shù)據(jù)庫中所有數(shù)據(jù)占用空間
SELECTconcat( round( sum( DATA_LENGTH / 1024 / 1024 ), 2 ), 'MB' ) AS DATA
FROMTABLES;
-- 查詢指定 數(shù)據(jù)庫 的 指定表 數(shù)據(jù)占用空間
SELECTconcat( round( sum( data_length / 1024 / 1024 ), 2 ), 'MB' ) AS DATA
FROM
TABLES
WHEREtable_schema = '{your database}' AND table_name = '{your table name}';
-- 查詢指定 數(shù)據(jù)庫 的 指定表 索引占用空間
SELECTconcat( round( sum( index_length / 1024 / 1024 ), 2 ), 'MB' ) AS DATA
FROM
TABLES
WHEREtable_schema = '{your database}' AND table_name = '{your table name}';
第三步:拿來即用
兩條潤色后的sql,可以直接很清晰地查詢 庫 和 表占用的大小。只需要修改參數(shù){your databse}即可
PS:必須先執(zhí)行第一步
-- 查詢庫中所有表的總和,分項列出
select
table_schema as '數(shù)據(jù)庫',
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='{your database}';
-- 查詢庫中每個表的空間占用,分項列出
select
table_schema as '數(shù)據(jù)庫',
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='{your database}'
order by data_length desc, index_length desc;
總結(jié)
以上是生活随笔為你收集整理的mysql 快捷查询数据库各表占用空间,mysql查看索引占用空间,mysql查看数据占用空间的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: /var/lib/docker/over
- 下一篇: 程序主动进行电话短信报警,自定义电话、短