现在的位置: 首页 > 数据库 > 正文

MySQL查看数据库表容量大小的方法

2020年02月20日 数据库 ⁄ 共 1433字 ⁄ 字号 评论关闭

  information_schema简介

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

  SCHEMATA表:提供了当前mysql实例中所有数据库的信息。

  TABLES表:提供了关于数据库中的表的信息(包括视图)。详细表述了某个表属于哪个schema,表类型,表引擎,创建时间等信息。

  COLUMNS表:提供了表中的列信息。详细表述了某张表的所有列以及每个列的信息。

  STATISTICS表:提供了关于表索引的信息。

  下面是使用information_schema表查看数据库信息的案例:

  查看所有数据库容量大小

  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

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

  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

  查看(指定库)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)'

  from information_schema.tables

  where table_schema='mysql';

  查看(指定库)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)'

  from information_schema.tables

  where table_schema='mysql'

  order by data_length desc, index_length desc;

  以上就是有关MySQL查看数据库表容量大小的方法的介绍了,要了解更多数据库知识请关注学步园。

抱歉!评论已关闭.