1. 程式人生 > >mysql命令-查詢資料庫佔用磁碟

mysql命令-查詢資料庫佔用磁碟

查詢所有的資料庫
USE information_schema;
SELECT TABLE_SCHEMA,
CONCAT(TRUNCATE(SUM(`data_length` + `index_length`)/1024/1024/1024,4),' GB') AS data,
CONCAT(TRUNCATE(SUM(`data_length`)/1024/1024,2),' MB') AS data_size,
CONCAT(TRUNCATE(SUM(`index_length`)/1024/1024,2),'MB') AS index_size
FROM information_schema.tables
GROUP
BY TABLE_SCHEMA ORDER BY SUM(`data_length` + `index_length`) DESC;

這裡寫圖片描述

查詢單個數據庫
USE information_schema;
SELECT TABLE_SCHEMA,
CONCAT(TRUNCATE(SUM(`data_length` + `index_length`)/1024/1024/1024,4),' GB') AS data,
CONCAT(TRUNCATE(SUM(`data_length`)/1024/1024,2),' MB') AS data_size,
CONCAT(TRUNCATE(SUM(`index_length`
)/1024/1024,2),'MB') AS index_size FROM information_schema.tables WHERE TABLE_SCHEMA = '資料庫名稱' GROUP BY TABLE_SCHEMA ORDER BY SUM(`data_length` + `index_length`) DESC;

這裡寫圖片描述