MySQL查看索引和数据所占内存

MySQL查看索引和数据所占内存

背景

我们在使用数据库的时候有时候需要看一下当前表中数据占用了多少内存索引占用了多少内存。这里介绍一下如何查询到。

解决

假设我现在要查询的表名叫做trade,可以使用如下SQL语句进行查询

select * from `information_schema`.`TABLES` where `TABLE_NAME` = 'trade';

这句sql可以查询出来当前数据库实例中所有数据库中的trade表的信息。在这个问题中我们需要关注的字段是DATA_LENGTH和INDEX_LENGTH。这里就是我们想要看的数据大小和索引大小,单位是byte。

引用官网对这两个字段的描述,感兴趣的小伙伴可以看下:

  • DATA_LENGTH
    For MyISAM, DATA_LENGTH is the length of the data file, in bytes.
    For InnoDB, DATA_LENGTH is the approximate amount of space allocated for the clustered index, in bytes. Specifically, it is the clustered index size, in pages, multiplied by the InnoDB page size.
    Refer to the notes at the end of this section for information regarding other storage engines.
  • INDEX_LENGTH
    For MyISAM, INDEX_LENGTH is the length of the index file, in bytes.
    For InnoDB, INDEX_LENGTH is the approximate amount of space allocated for non-clustered indexes, in bytes. Specifically, it is the sum of non-clustered index sizes, in pages, multiplied by the InnoDB page size.
    Refer to the notes at the end of this section for information regarding other storage engines.
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值