专注于 JetBrains IDEA 全家桶,永久激活,教程
持续更新 PyCharm,IDEA,WebStorm,PhpStorm,DataGrip,RubyMine,CLion,AppCode 永久激活教程

MySQL查看数据库表容量大小和磁盘空间占用大小

information_schema表

在MySQL中,把 information_schema 看作是一个信息数据库。其中保存着关于MySQL服务器所维护的所有其他数据库的信息。如数据库名,数据库的表,表栏的数据类型与访问权限等。

information_schema中的表主要有:

  schemata表:这个表里面主要是存储在mysql中的所有的数据库的信息

  tables表:这个表里存储了所有数据库中的表的信息,包括每个表有多少个列等信息。

  columns表:这个表存储了所有表中的表字段信息。

  statistics表:存储了表中索引的信息。

  user_privileges表:存储了用户的权限信息。

  schema_privileges表:存储了数据库权限。

  table_privileges表:存储了表的权限。

  column_privileges表:存储了列的权限信息。

  character_sets表:存储了mysql可以用的字符集的信息。

  collations表:提供各个字符集的对照信息。

  collation_character_set_applicability表:相当于collations表和character_sets表的前两个字段的一个对比,记录了字符集之间的对照信息。

  table_constraints表:这个表主要是用于记录表的描述存在约束的表和约束类型。

  key_column_usage表:记录具有约束的列。

  routines表:记录了存储过程和函数的信息,不包含自定义的过程或函数信息。

  views表:记录了视图信息,需要有show view权限。

  triggers表:存储了触发器的信息,需要有super权限。

MySQL查看数据库表容量大小

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

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.查看所有数据库各表容量大小

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.查看指定数据库容量大小

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.查看指定数据库各表容量大小

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;

Mysql查看数据库,表占用磁盘大小

1、查询所有数据库占用磁盘空间大小

select 
TABLE_SCHEMA, 
concat(truncate(sum(data_length)/1024/1024,2),' MB') as data_size,
concat(truncate(sum(index_length)/1024/1024,2),' MB') as index_size
from information_schema.tables
group by TABLE_SCHEMA
ORDER BY data_size desc;

2、查询单个库中所有表磁盘占用大小

select 
TABLE_NAME, 
concat(truncate(data_length/1024/1024,2),' MB') as data_size,
concat(truncate(index_length/1024/1024,2),' MB') as index_size
from information_schema.tables 
where TABLE_SCHEMA = '查询的表名'
group by TABLE_NAME
order by data_length desc;

#

汇总学习使用,更多好的方法继续更新…

文章永久链接:https://tech.souyunku.com/18979

未经允许不得转载:搜云库技术团队 » MySQL查看数据库表容量大小和磁盘空间占用大小

JetBrains 全家桶,激活、破解、教程

提供 JetBrains 全家桶激活码、注册码、破解补丁下载及详细激活教程,支持 IntelliJ IDEA、PyCharm、WebStorm 等工具的永久激活。无论是破解教程,还是最新激活码,均可免费获得,帮助开发者解决常见激活问题,确保轻松破解并快速使用 JetBrains 软件。获取免费的破解补丁和激活码,快速解决激活难题,全面覆盖 2024/2025 版本!

联系我们联系我们