关于mysql 查看表大小的方法浅谈

182 篇文章 0 订阅

本文主要介绍了mysql 查看表大小的方法实践,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

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

1

2

3

4

5

6

7

8

select

table_schema as '数据库',

sum(table_rows) as '记录数',

sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)',

sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)'

from information_schema.tables

group by table_schema

order by sum(data_length) desc, sum(index_length) desc;

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

1

2

3

4

5

6

7

8

select

table_schema as '数据库',

table_name as '表名',

table_rows as '记录数',

truncate(data_length/1024/1024, 2) as '数据容量(MB)',

truncate(index_length/1024/1024, 2) as '索引容量(MB)'

from information_schema.tables

order by data_length desc, index_length desc;

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

例:查看mysql库容量大小:代码如下:

1

2

3

4

5

6

7

select

table_schema as '数据库',

sum(table_rows) as '记录数',

sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)',

sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)'

from information_schema.tables

where table_schema='mysql';

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

例:查看mysql库各表容量大小

1

2

3

4

5

6

7

8

9

select

table_schema as '数据库',

table_name as '表名',

table_rows as '记录数',

truncate(data_length/1024/1024, 2) as '数据容量(MB)',

truncate(index_length/1024/1024, 2) as '索引容量(MB)'

from information_schema.tables

where table_schema='mysql'

order by data_length desc, index_length desc;

PS:查看MySql数据空间使用情况:

information_schema是MySQL的系统数据库,information_schema里的tables表存放了整个数据库各个表的使用情况。

可以使用sql来统计出数据库的空间使用情况,相关字段:

  • table_schema:数据库名
  • table_name:表名
  • table_rows:记录数
  • data_length:数据大小
  • index_length:索引大小

使用空间

1、统计表使用空间

1

select concat(round(sum(data_length/1024/1024),2),'mb') as data from tables where table_schema='mydb' and table_name='mytable';

| data |

| 0.02mb |

1 row in set (0.00 sec)

2、统计数据库使用空间

1

select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='mydb';

| data |

| 6.64MB |

1 row in set (0.00 sec)

3、统计所有数据使用空间

1

select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;

| data |

| 6.64MB |

1 row in set (0.01 sec)

 到此这篇关于mysql 查看表大小的方法实践的文章就介绍到这了,希望可以帮到你。

来源:微点阅读  https://www.weidianyuedu.com

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值