查询数据库大小和表大小
查询数据库总大小
SELECT
concat( round( sum( data_length / 1024 / 1024 ), 2 ), 'MB' ) AS DATA
FROM
information_schema.TABLES;
查询所有库的大小
SELECT
table_schema AS '数据库',
concat( TRUNCATE ( data_length / 1024 / 1024, 2 ), ' MB' ) AS '数据容量(MB)',
concat( TRUNCATE ( index_length / 1024 / 1024, 2 ), ' MB' ) AS '索引容量(MB)'
FROM
information_schema.TABLES
GROUP BY
TABLE_SCHEMA
ORDER BY
data_length DESC;
查询某个库中所有表的大小
SELECT
TABLE_NAME as '表名',
concat( TRUNCATE ( data_length / 1024 / 1024, 2 ), ' MB' ) AS '数据大小(MB)',
concat( TRUNCATE ( index_length / 1024 / 1024, 2 ), ' MB' ) AS '索引大小(MB)'
FROM
information_schema.TABLES
WHERE
TABLE_SCHEMA = 'enterprise'
GROUP BY
TABLE_NAME
ORDER BY
data_length DESC;
查询指定数据库的大小
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 = 'enterprise';
查询指定表的大小
SELECT
concat( round( sum( DATA_LENGTH / 1024 / 1024 ), 2 ), 'MB' ) AS DATA
FROM
information_schema.TABLES
WHERE
table_schema = 'enterprise'
AND table_name = 'customeventdictionary';

浙公网安备 33010602011771号