当前位置:主页 > 查看内容

一文看懂MySQL如何查看数据库表容量大小

发布时间:2021-06-16 00:00| 位朋友查看

简介:今天主要介绍MySQL查看数据库表容量大小的几个方法,仅供参考。 1. 查看所有数据库容量大小 SELECT table_schemaAS'数据库', sum(table_rows)AS'记录数', sum(TRUNCATE(data_length/1024/1024,2))AS'数据容量(MB)', sum(TRUNCATE(index_length/1024/1024,2))……

今天主要介绍MySQL查看数据库表容量大小的几个方法,仅供参考。

1. 查看所有数据库容量大小

  1. SELECT 
  2.     table_schema AS '数据库', 
  3.     sum( table_rows ) AS '记录数', 
  4.     sum( TRUNCATE ( data_length / 1024 / 1024, 2 ) ) AS '数据容量(MB)', 
  5.     sum( TRUNCATE ( index_length / 1024 / 1024, 2 ) ) AS '索引容量(MB)'  
  6. FROM 
  7.     information_schema.TABLES  
  8. GROUP BY 
  9.     table_schema  
  10. ORDER BY 
  11.     sum( data_length ) DESC, 
  12.     sum( index_length ) DESC; 

一文看懂MySQL如何查看数据库表容量大小

2. 查看所有数据库各表容量大小

  1. SELECT 
  2.     table_schema AS '数据库', 
  3.     table_name AS '表名', 
  4.     table_rows AS '记录数', 
  5.     TRUNCATE ( data_length / 1024 / 1024, 2 ) AS '数据容量(MB)', 
  6.     TRUNCATE ( index_length / 1024 / 1024, 2 ) AS '索引容量(MB)'  
  7. FROM 
  8.     information_schema.TABLES  
  9. ORDER BY 
  10.     data_length DESC, 
  11.     index_length DESC; 

一文看懂MySQL如何查看数据库表容量大小

3. 查看指定数据库容量大小

  1. SELECT 
  2.     table_schema AS '数据库', 
  3.     sum( table_rows ) AS '记录数', 
  4.     sum( TRUNCATE ( data_length / 1024 / 1024, 2 ) ) AS '数据容量(MB)', 
  5.     sum( TRUNCATE ( index_length / 1024 / 1024, 2 ) ) AS '索引容量(MB)'  
  6. FROM 
  7.     information_schema.TABLES  
  8. WHERE 
  9.     table_schema = 'mysql'

一文看懂MySQL如何查看数据库表容量大小

4. 查看指定数据库各表容量大小

  1. SELECT 
  2.     table_schema AS '数据库', 
  3.     table_name AS '表名', 
  4.     table_rows AS '记录数', 
  5.     TRUNCATE ( data_length / 1024 / 1024, 2 ) AS '数据容量(MB)', 
  6.     TRUNCATE ( index_length / 1024 / 1024, 2 ) AS '索引容量(MB)'  
  7. FROM 
  8.     information_schema.TABLES  
  9. WHERE 
  10.     table_schema = 'mysql'  
  11. ORDER BY 
  12.     data_length DESC, 
  13.     index_length DESC; 


本文转载自网络,原文链接:https://www.toutiao.com/i6736043603589612045/
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!
上一篇:MySQL EXPLAIN结果集分析 - 附带大量案例 下一篇:没有了

推荐图文


随机推荐