一、查看所有数据库容量大小

二、查看所有数据库各表容量大小

三、查看指定数据库容量大小

四、查看指定数据库各表容量大小

五:查看指定数据库指定表容量大小


数据库情况

一、查看所有数据库容量大小

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 GROUPBY	table_schema ORDERBY	sum( data_length ) DESC,	sum( index_length ) DESC;

结果:

二、查看所有数据库各表容量大小

SELECT	table_schema AS'数据库',	table_name AS'表名',	table_rows AS'记录数',	TRUNCATE ( data_length / 1024 / 1024, 2 ) AS'数据容量(MB)',	TRUNCATE ( index_length / 1024 / 1024, 2 ) AS'索引容量(MB)' FROM	information_schema.TABLES ORDERBY	data_length DESC,	index_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 ='test';

结果:其中记录数为数据行数

四、查看指定数据库各表容量大小

SELECT	table_schema AS'数据库',	table_name AS'表名',	table_rows AS'记录数',	TRUNCATE ( data_length / 1024 / 1024, 2 ) AS'数据容量(MB)',	TRUNCATE ( index_length / 1024 / 1024, 2 ) AS'索引容量(MB)' FROM	information_schema.TABLES WHERE	table_schema = 'test' ORDERBY	data_length DESC,	index_length DESC;

结果:

五:查看指定数据库指定表容量大小

SELECT	table_schema AS'数据库',	table_name AS'表名',	table_rows AS'记录数',	TRUNCATE ( data_length / 1024 / 1024, 2 ) AS'数据容量(MB)',	TRUNCATE ( index_length / 1024 / 1024, 2 ) AS'索引容量(MB)' FROM	information_schema.TABLES WHERE	table_schema = 'test' 	AND table_name = 'user';

结果:

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐