MYSQL 查看数据占用大小

在mysql中有一个默认的数据表information_schema,information_schema这张数据表保存了MySQL服务器所有数据库的信息。如数据库名,数据库的表,表栏的数据类型与访问权限等。再简单点,这台MySQL服务器上,到底有哪些数据库、各个数据库有哪些表,每张表的字段类型是什么,各个数据库要什么权限才能访问,等等信息都保存在information_schema表里面。

1、查看数据库使用情况

索引大小 + 数据大小 = 总大小

SELECT CONCAT(ROUND(SUM(index_length)/(1024*1024), 2), 'MB') AS 'Total Index Size' ,
CONCAT(ROUND(SUM(data_length)/(1024*1024), 2), ' MB') AS 'Total Data Size' ,
CONCAT(ROUND(SUM(index_length+data_length)/(1024*1024), 2), ' MB') AS 'Total Size'
FROM information_schema.TABLES WHERE table_schema LIKE '数据库名'; 

查看表占用

表名、行数、数据大小、索引大小、总大小

SELECT CONCAT(table_schema,'.',table_name) AS 'Table Name', 
table_rows AS 'Number of Rows', 
CONCAT(ROUND(data_length/(1024*1024*1024),6),' G') AS 'Data Size', 
CONCAT(ROUND(index_length/(1024*1024*1024),6),' G') AS 'Index Size' , 
CONCAT(ROUND((data_length+index_length)/(1024*1024*1024),6),' G') AS'Total'
FROM information_schema.TABLES 
WHERE table_schema = '数据库名';
原文地址:https://www.cnblogs.com/connected/p/14041379.html