MySQL數(shù)據(jù)和索引占用空間查詢
查詢所有數(shù)據(jù)庫占用磁盤空間大小的SQL語句
SELECT
table_schema, -- 數(shù)據(jù)庫名稱
concat( TRUNCATE ( sum( data_length ) / 1024 / 1024, 2 ), 'MB' ) AS data_size, -- 數(shù)據(jù)占用空間
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 ) DESC;
查詢單個(gè)庫中所有表磁盤占用大小的SQL語句
SELECT
table_name, -- 表名稱
concat( TRUNCATE ( data_length / 1024 / 1024, 2 ), 'MB' ) AS data_size, -- 數(shù)據(jù)占用空間
concat( TRUNCATE ( index_length / 1024 / 1024, 2 ), 'MB' ) AS index_size -- 索引占用空間
FROM
information_schema.TABLES
WHERE
table_schema = '數(shù)據(jù)庫名稱'
ORDER BY
data_length DESC;
趙小胖個(gè)人博客:https://zc.happyloves.cn:4443/wordpress/