首页 » web 后端 »

查询MySQL数据库所占用大小

2019年08月17日 web 后端 2608 views 0 0

扫一扫用手机浏览

/*查询MySQL数据库里面的所有数据库各自占用大小*/ 

select TABLE_SCHEMA, concat(truncate(sum(data_length)/1024/1024,2),' MB') as data_size, concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size from information_schema.tables group by TABLE_SCHEMA order by data_length desc; 

 /*查询MySQL数据库里面的单个数据库占用大小*/ 

SELECT CONCAT(TRUNCATE(SUM(data_length)/1024/1024,2),'MB') AS data_size, CONCAT(TRUNCATE(SUM(max_data_length)/1024/1024,2),'MB') AS max_data_size, CONCAT(TRUNCATE(SUM(data_free)/1024/1024,2),'MB') AS data_free, CONCAT(TRUNCATE(SUM(index_length)/1024/1024,2),'MB') AS index_size FROM information_schema.tables WHERE TABLE_SCHEMA = '数据库名'; 

 /*查询MySQL数据库里面的单个数据库所有表各自占用大小*/

 select TABLE_NAME, concat(truncate(data_length/1024/1024,2),' MB') as data_size, concat(truncate(index_length/1024/1024,2),' MB') as index_size from information_schema.tables where TABLE_SCHEMA = '数据库名' group by TABLE_NAME order by data_length desc;  

/*查询MySQL数据库里面的单个数据库指定表占用大小*/ 

SELECT CONCAT(TRUNCATE(SUM(data_length)/1024/1024,2),'MB') AS data_size, CONCAT(TRUNCATE(SUM(max_data_length)/1024/1024,2),'MB') AS max_data_size, CONCAT(TRUNCATE(SUM(data_free)/1024/1024,2),'MB') AS data_free, CONCAT(TRUNCATE(SUM(index_length)/1024/1024,2),'MB') AS index_size FROM information_schema.tables WHERE TABLE_NAME = '表名';

赞(0
  • 微信
  • 支付宝

感谢您的支持!点击关闭

注:本文转载自互联网,如有侵权,联系删除

发表评论