用MySQL内置的数据库 information_schema,该数据库中的tables表保存了数据库中所有表的信息。
use information_schema;
describe tables;

得到表的大小相关的字段:
- TABLE_SCHEMA:表所属数据库名
- TABLE_NAME:表名
- TABLE_ROWS:该表中的记录数
- DATA_LENGTH:数据总大小
- INDEX_LENGTH:索引总大小
查看employees数据库中所有表的大小:
select table_name,table_rows,data_length+index_length,concat(round((data_length+index_length)/1024/1024,2),'MB') data from tables where table_schema='employees';

查看employees数据库中employees表的大小:
select table_name,table_rows,data_length+index_length,
concat(round((data_length+index_length)/1024/1024,2),'MB')
data from tables where table_schema='employees'
and table_name='employees';

本文介绍如何使用MySQL的information_schema数据库来查询表的大小,包括记录数、数据总大小及索引总大小。通过SQL语句展示如何获取指定数据库或表的具体信息。
4989

被折叠的 条评论
为什么被折叠?



