首页 > 数据库 >如何查看 MySQL 数据库容量大小,表容量大小,索引容量大小?找到占用空间最大的表

如何查看 MySQL 数据库容量大小,表容量大小,索引容量大小?找到占用空间最大的表

时间:2022-10-09 15:24:12浏览次数:49  
标签:1024 truncate 容量 MB length MySQL 大小 table schema

1. 查看 MySQL「所有库」的容量大小

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)',
sum(truncate(DATA_FREE/1024/1024, 2)) as '碎片占用(MB)'
from information_schema.tables
group by table_schema
order by sum(data_length) desc, sum(index_length) desc;

2. 查看 MySQL「指定库」的容量大小

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)',
sum(truncate(DATA_FREE/1024/1024, 2)) as '碎片占用(MB)'
from information_schema.tables
where table_schema='kalacloud_test_data'
order by data_length desc, index_length desc;

3. 查看 MySQL「指定库」中「所有表」的容量大小

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)',
  truncate(DATA_FREE/1024/1024, 2) as '碎片占用(MB)'
from 
  information_schema.tables
where 
  table_schema='kalacloud_test_data'
order by 
  data_length desc, index_length desc;

4. 查看 MySQL「指定库」中「指定表」的容量大小

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)',
  truncate(DATA_FREE/1024/1024, 2) as '碎片占用(MB)'
from 
  information_schema.tables
where 
  table_schema='kalacloud_test_data'and table_name='product_demo'
order by 
  data_length desc, index_length desc;

5. 查看 MySQL 数据库中,容量排名前 10 的表

USE information_schema;
SELECT 
  TABLE_SCHEMA as '数据库',
  table_name as '表名',
  table_rows as '记录数',
  ENGINE as '存储引擎',
  truncate(data_length/1024/1024, 2) as '数据容量(MB)',
  truncate(index_length/1024/1024, 2) as '索引容量(MB)',
  truncate(DATA_FREE/1024/1024, 2) as '碎片占用(MB)'
from  tables 
order by table_rows desc limit 10;

6. 查看 MySQL「指定库」中,容量排名前 10 的表

USE information_schema;
SELECT 
  TABLE_SCHEMA as '数据库',
  table_name as '表名',
  table_rows as '记录数',
  ENGINE as '存储引擎',
  truncate(data_length/1024/1024, 2) as '数据容量(MB)',
  truncate(index_length/1024/1024, 2) as '索引容量(MB)',
  truncate(DATA_FREE/1024/1024, 2) as '碎片占用(MB)'
from  tables 
where 
  table_schema='kalacloud_test_data' 
order by table_rows desc limit 10;

 

标签:1024,truncate,容量,MB,length,MySQL,大小,table,schema
From: https://www.cnblogs.com/raorao1994/p/16772233.html

相关文章

  • mysql之select使用篇1
    一、sql概述、规则数据导入1、sql概述sql有两个重要的标准分贝是sql92和sql96标准,今天使用sql一直遵循这两个标准,不通的数据库生产厂商都支持sql语句,但是也各有特有的内容2......
  • Mysql字符集
    1、修改MySQL5.7字符集我们在新建数据库时(Navicat)界面时会遇到这两个选项,字符集和排序规则在MySQL8.0版本之前,MySQL5.7默认的客户端和服务器都用了latin1,而latin1是不......
  • mysql 大小写、sql_mode
    一、mysql大小写1、Windows和Linux平台区别在SQL中,关键字和函数名是不用区分字母大小写的,比如SELECT、WHERE、ORDER、GROUPBY等关键字,以及ABS、MOD、ROUND、MAX等......
  • mysql数据库目录
    一、mysql相关目录查看和mysql相关的目录命令find/-namemysql1、数据库文件存放路径其中/var/lib/mysql/就是mysql数据库文件存放路径,当然也可通过命令查看mysql>s......
  • mysql之select查询篇2
    一、多表查询1、多表查询概述1.1、为什么要多表查询执行多条单表查询语句延时数据放在一个表出现字段数据冗余1.2、笛卡尔积错误selectuseriddepnamefromuser,dep出现每......
  • MYSQL-->触发器
    介绍触发器是与表有关的数据项,指在insert/update/delete之前或之后,出发并执行触发器中定义的SQL语句集合。触发器的这种特性可以协助应用在数据库端确保数据的完整性,日......
  • 案例分享:Qt工程机械真空激光焊接系统软件产品定制(西门子PLC,mysql数据库,用户权限控制,界
    需求  1.触摸屏控制,按照客户需求,ui由本司美工承担设计,显示分辨率1280x1024,同时支持鼠标操作。  2.权限控制:三种权限,分为管理员(可以定制模块界面,修改产品名称等定制......
  • 视频直播源码,插入图片、删除图片、设置图片大小、提取图片
    视频直播源码,插入图片、删除图片、设置图片大小、提取图片1.插入图片Document对象有一个add_paragraph()方法插入图片,只需要传入路径或者字节流即可,实际上它也是调用段落......
  • mysql 用户授权
    mysql用户授权:1.创建用户:createuser'user1'@'100.%'identifiedby'pwd'//创建用户并无权限2.授权:grantallprivilegeson*.*TO'user1'@'100.%'withgrantopt......
  • mysql 中sql 语句查询今天、昨天、近7天、近30天、一个月内、上一月 数据
    几个小时内的数据DATE_SUB(NOW(),INTERVAL5HOUR)今天select * from 表名 where to_days(时间字段名) = to_days(now());昨天SELECT * FROM 表名 WHERE T......