天选集结号活动中心

天选集结号活动中心

shape
  • Home
  • 官方合作
  • [913]MySQL查看数据库表容量大小

[913]MySQL查看数据库表容量大小

  • 2026-01-14 08:55:11
  • admin

查看一个数据中所有表的相关信息:

(1)可以在命令下使用show table status \G命令查看:

(2)如果想知道MySQL数据库中每个表占用的空间、表记录的行数的话,可以打开MySQL的 information_schema 数据库。在该库中有一个 TABLES 表,这个表主要字段分别是:

TABLE_SCHEMA : 数据库名

TABLE_NAME:表名

ENGINE:所使用的存储引擎

TABLES_ROWS:记录数

DATA_LENGTH:数据大小

INDEX_LENGTH:索引大小

其他字段请参考MySQL的手册,我们只需要了解这几个就足够了。所以要知道一个表占用空间的大小,那就相当于是 数据大小 + 索引大小 即可。

1.查看所有数据库容量大小代码语言:txt复制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.查看所有数据库各表容量大小代码语言:txt复制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.查看指定数据库容量大小例:查看mysql库容量大小

代码语言:txt复制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.查看指定数据库各表容量大小例:查看mysql库各表容量大小

代码语言:txt复制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;参考:https://www.cnblogs.com/dekevin/p/10276832.html

https://blog.csdn.net/helloxiaozhe/article/details/88599777

<<<
Previous Post
支付宝“借呗”没了?!官方回应

Copyright © 2088 天选集结号活动中心 All Rights Reserved.

友情链接