zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

详解MySQL查看数据库表容量大小的方法总结

2023-03-14 22:23:55 时间

详解MySQL查看数据库表容量大小的方法总结

概述

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

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

  1. SELECT 
  2.     table_schema AS '数据库'
  3.     sum( table_rows ) AS '记录数'
  4.     sumTRUNCATE ( data_length / 1024 / 1024, 2 ) ) AS '数据容量(MB)'
  5.     sumTRUNCATE ( 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.     sumTRUNCATE ( data_length / 1024 / 1024, 2 ) ) AS '数据容量(MB)'
  5.     sumTRUNCATE ( 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
详解MySQL查看数据库表容量大小的方法总结