MySQL查看庫和表容量大小方法

MySQL查看庫和表容量大小方法

-- 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.查看指定數據庫容量大小
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='weiya_chat';
-- 3.查看指定數據庫各表容量大小
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='weiya_chat' ORDER BY data_length desc, index_length desc;
-- 4.查看所有數據庫各表容量大小
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;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章