1.查看所有數(shù)據(jù)庫(kù)容量大小
SELECT
table_schema AS '數(shù)據(jù)庫(kù)',
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
GROUP BY
table_schema
ORDER BY
sum( data_length ) DESC,
sum( index_length ) DESC;
2.查看所有數(shù)據(jù)庫(kù)各表容量大小
SELECT
table_schema AS '數(shù)據(jù)庫(kù)',
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
ORDER BY
data_length DESC,
index_length DESC;
3.查看指定數(shù)據(jù)庫(kù)容量大小
SELECT
table_schema AS '數(shù)據(jù)庫(kù)',
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 = '數(shù)據(jù)庫(kù)名';
4.查看指定數(shù)據(jù)庫(kù)各表容量大小
SELECT
table_schema AS '數(shù)據(jù)庫(kù)',
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 = '數(shù)據(jù)庫(kù)名'
ORDER BY
data_length DESC,
index_length DESC;
5.查看指定數(shù)據(jù)庫(kù)各表信息
SHOW TABLE STATUS;
參考:
TABLE_SCHEMA : 數(shù)據(jù)庫(kù)名
TABLE_NAME:表名
ENGINE:所使用的存儲(chǔ)引擎
TABLE_ROWS:記錄數(shù)
DATA_LENGTH:數(shù)據(jù)大小
INDEX_LENGTH:索引大小
BYTE(B):字節(jié)
1KB ,2 的 10 次方 : 1024 BYTE.
1MB 傲宜,2 的 20 次方 : 1024 KB.
1GB ,2 的 30 次方 : 1024 MB.
1TB ,2 的 40 次方 : 1024 GB.
1PB 澜建,2 的 50 次方 : 1024 TB.
1EB ,2 的 60 次方 : 1024 PB.
1ZB ,2 的 70 次方 : 1024 EB.
1YB ,2 的 80 次方 : 1024 ZB.