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

database

  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;

 

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

以上是 MySQL查看数据库表容量大小和磁盘空间占用大小 的全部内容, 来源链接: utcz.com/z/534384.html

回到顶部