tx

wangcx

栖迟於一丘,则天下不易其乐
42,859
查询指定数据库每张表、索引占用磁盘空间大小及汇总 查询指定数据库每张表、索引占用磁盘空间大小及汇总
SELECT COALESCE
    ( bb.表名, '汇总' ) AS "表名",
    bb.记录数,
    bb.数据容量(GB),
    bb.索引容量(GB) 
FROM
    (
SELECT
    aa.表名,
    sum( AA.记录数 ) AS "记录数",
    sum( AA.数据容量(GB) ) AS "数据容量(GB)",
    sum( AA.索引容量(GB) ) AS "索引容量(GB)" 
FROM
    (
SELECT
    table_schema "数据库",
    table_name AS "表名",
    table_rows AS "记录数",
    TRUNCATE ( data_length / 1024 / 1024, 2 ) / 1024 AS "数据容量(GB)",
    TRUNCATE ( index_length / 1024 / 1024, 2 ) / 1024 AS "索引容量(GB)" 
FROM
    information_schema.TABLES 
WHERE
    table_schema = 'test' 
ORDER BY
    data_length DESC,
    index_length DESC 
    ) AA 
GROUP BY
    aa.表名 WITH ROLLUP 
    ) bb 
ORDER BY
    bb.数据容量(GB) DESC,
    bb.索引容量(GB) DESC;
0 条评论
user 编辑评论信息
插入图片

隐私评论

随机一言

:D 获取中...

文章目录

最新评论

随机文章

Mac 下安装 Homebrew 646 浏览 - 2020/05/11
LogBack 日志路径配置问题 760 浏览 - 2022/04/26
网站搬迁到野草云香港服务器 450 浏览 - 2024/05/18
MySQL 插入时间错误问题 491 浏览 - 2021/01/29