欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

MySQL统计数据库表大小 mysqlSCHEMAsql 

程序员文章站 2022-04-24 08:28:11
...
1、统计指定数据库大小:
SELECT 
	TABLE_SCHEMA 
	,CONCAT(ROUND(SUM(DATA_LENGTH/1024/1024),2),'M') AS 'DATA_LENGTH_MB'
	,CONCAT(ROUND(SUM(INDEX_LENGTH/1024/1024),2),'M') AS 'INDEX_LENGTH_MB'
	,CONCAT(ROUND(SUM(DATA_LENGTH/1024/1024)+SUM(INDEX_LENGTH/1024/1024),2),'M') AS 'TOTAL_LENGTH_MB'
FROM information_schema.tables 
WHERE table_schema='scpnf';


2、查询指定数据库下各表大小
select 
	 t.`TABLE_SCHEMA` as '数据库名称'
	,t.`TABLE_NAME` as '表名称'
	,CONCAT(ROUND(data_length/1024/1024,2),'M') as '数据大小(MB)'
	,CONCAT(ROUND(index_length/1024/1024,2),'M')  as '索引大小(MB)'
from `TABLES` t
where  t.`TABLE_SCHEMA` = 'scpnf'
order by t.`DATA_LENGTH` desc

相关标签: mysql SCHEMA sql