【问题标题】:Mysql list tables and sizes - order by sizeMysql 列出表和大小 - 按大小排序
【发布时间】:2013-01-12 06:11:42
【问题描述】:

在 mysql 中按大小按数据库顺序列出所有表的查询是什么?

【问题讨论】:

标签: mysql


【解决方案1】:

试试这个...

SELECT TABLE_NAME, table_rows, data_length, index_length, 
round(((data_length + index_length) / 1024 / 1024),2) "Size in MB"
FROM information_schema.TABLES WHERE table_schema = "schema_name"
ORDER BY (data_length + index_length) DESC;

注意:将上面的 schema_name 替换为您的数据库名称

【讨论】:

    【解决方案2】:

    在 mysql 客户端中运行以下查询

    SELECT table_name AS "Tables", 
    round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB" 
    FROM information_schema.TABLES 
    WHERE table_schema = "$DB_NAME"
    ORDER BY (data_length + index_length) DESC;
    

    【讨论】:

      【解决方案3】:

      在 information_schema 数据库中执行以下查询:

      SELECT table_schema AS "Database name",
      SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)" 
      FROM information_schema.TABLES 
      GROUP BY table_schema 
      ORDER BY (SUM(data_length + index_length) / 1024 / 1024) DESC;
      

      【讨论】:

        猜你喜欢
        • 2014-03-11
        • 1970-01-01
        • 1970-01-01
        • 2013-06-21
        • 1970-01-01
        • 2019-03-11
        • 1970-01-01
        • 2013-06-28
        • 2018-11-17
        相关资源
        最近更新 更多