首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫

MySQL 表空間與索引大小查詢:information_schema 實用 SQL

     編輯:MySQL 資料庫相關知識

1. 總索引大小(GB/MB)

-- GB
SELECT CONCAT(ROUND(SUM(index_length)/(1024*1024*1024),2),' GB') AS 'Total Index Size'
FROM information_schema.TABLES WHERE table_schema='db_name';

-- MB
SELECT CONCAT(ROUND(SUM(index_length)/(1024*1024),2),' MB') AS 'Total Index Size'
FROM information_schema.TABLES WHERE table_schema='db_name';

2. 總數據大小(表空間)

SELECT CONCAT(ROUND(SUM(data_length)/(1024*1024*1024),2),' GB') AS 'Total Data Size'
FROM information_schema.TABLES WHERE table_schema='db_name';

3. 所有表詳細信息

SELECT
  CONCAT(table_schema,'.',table_name) AS 'Table Name',
  CONCAT(ROUND(table_rows/1000000,2),'M') AS 'Rows',
  CONCAT(ROUND(data_length/(1024*1024*1024),2),'G') AS 'Data Size',
  CONCAT(ROUND(index_length/(1024*1024*1024),2),'G') AS 'Index Size',
  CONCAT(ROUND((data_length+index_length)/(1024*1024*1024),2),'G') AS 'Total'
FROM information_schema.TABLES
WHERE table_schema='db_name';

適用於容量規劃、分庫分表前評估、索引膨脹監控。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved