MySq 表内存占用情况

 

Mysql查询数据库表内存占用情况,按照表名分组

SELECT   table_schema  AS '数据库名称',table_name AS '数据表名' ,table_rows  AS '数据条数(条)'
,ROUND((data_length + index_length) / 1024/ 1024, 2) AS '数据库大小(MB)',ROUND((data_length + index_length) / 1024/1024/ 1024, 2) AS '数据库大小(GB)'
,create_time  AS '创建时间',update_time  AS '最后更新时间'
 from information_schema.`TABLES`  
 WHERE table_schema='dbname'   -- 数据库名称 
  ORDER BY table_rows desc ;

 

Mysql查询整个数据库内存占用情况,按照数据库分组

SELECT * from (
SELECT table_schema AS '数据库名称',ROUND(SUM(table_rows ) , 2) AS AllRows,ROUND(SUM(data_length + index_length) / 1024/ 1024, 2) AS '数据库大小(MB)',ROUND(SUM(data_length + index_length) / 1024/1024/ 1024, 2) AS '数据库大小(GB)'
 
 
 from information_schema.`TABLES` 
 
gROUP BY table_schema

) as tt

ORDER BY tt.AllRows DESC 

  

 

posted @ 2024-06-26 15:03  人生为卒  阅读(1)  评论(0编辑  收藏  举报