Home > Database > Mysql Tutorial > body text

MySQL数据库查看数据表占用空间大小和记录数的方法_MySQL

WBOY
Release: 2016-06-01 13:00:30
Original
1166 people have browsed it

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

TABLE_SCHEMA : 数据库名
TABLE_NAME:表名
ENGINE:所使用的存储引擎
TABLES_ROWS:记录数
DATA_LENGTH:数据大小
INDEX_LENGTH:索引大小

其他字段请参考MySQL的手册,这几个字段对我们来说最有用。
一个表占用空间的大小,相当于是 数据大小 + 索引大小,

示例:

1.想查看hx库的所有表大小,可以使用:

代码如下:


SELECT TABLE_NAME,DATA_LENGTH+INDEX_LENGTH,TABLE_ROWS FROM information_schema.TABLES WHERE TABLE_SCHEMA='hx';

+-------------------+--------------------------+------------+
| TABLE_NAME        | DATA_LENGTH+INDEX_LENGTH | TABLE_ROWS |
+-------------------+--------------------------+------------+
| enjoy_data    |                  6979584 |      70113 |
| hx_record      |                113410048 |     753279 |
| itlearner_record       |              21835546624 |  104917777 |
| tmp_day_id        |                    17326 |        811 |
+-------------------+--------------------------+------------+


2.想查看hx库的enjoy表大小,可以使用:

代码如下:


SELECT DATA_LENGTH+INDEX_LENGTH,TABLE_ROWS FROM information_schema.TABLES WHERE TABLE_SCHEMA='hx' AND TABLE_NAME = 'enjoy_data';


返回:

代码如下:


+--------------------------+------------+
| DATA_LENGTH+INDEX_LENGTH | TABLE_ROWS |
+--------------------------+------------+
|                     6979584 |          70113 |
+--------------------------+------------+

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!