mysql查询数据量

本文介绍了如何通过MySQL的information_schema库来查询数据库、特定数据库以及具体表的数据总量。首先,通过`use information_schema`切换到该库,然后利用SQL查询语句计算数据长度并转换为MB单位。示例中分别展示了查询所有数据库、pay数据库以及pay数据库中match表的数据量。
摘要由CSDN通过智能技术生成

所有查询都需要进入到information_schema库进行操作

进入information_schema库命令

mysql> use information_schema;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

1、查询数据库数据总量

mysql> select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;
+-------------+
| data        |
+-------------+
| 114801.17MB |
+-------------+
1 row in set (0.09 sec)

2、查询某个数据库的数据量,此处为pay库

mysql> select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='pay';
+-----------+
| data      |
+-----------+
| 1695.94MB |
+-----------+
1 row in set (0.01 sec)

3、查询某个表的数据量,此处为pay数据库中的match

        (1).查询pay库中的所有表名

mysql> select table_name from information_schema.tables where table_schema='pay';
+------------------------------+
| table_name                   |
+------------------------------+
| avgTable                     |
| avgTable1                    |
| avgTable2                    |
| confirm_relation             |
| match                        |
+------------------------------+

        (2).查看pay数据库中的match表

mysql> select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='pay' and table_name='match';
+--------+
| data   |
+--------+
| 0.02MB |
+--------+
1 row in set (0.01 sec)

  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT.小唐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值