MySQL如何统计数据库及数据库中表大小,大部分程序员都收藏了...

统计指定数据库大小
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='kcms';
执行效果:

查询指定数据库下各表大小
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='kcms';
执行效果:
