Home >Database >Mysql Tutorial >mysql统计一张表中条目个数的方法_MySQL

mysql统计一张表中条目个数的方法_MySQL

WBOY
WBOYOriginal
2016-06-01 13:02:191133browse

统计一张表中条目的个通常的SQL语句是:

select count(*) from tableName;

#or
select count(<strong>1</strong>) from tableName;
#or 统计一个列项,如ID
select count(ID)

另外,可通过使用information_schema统计个数

MySQL中有一个名为 information_schema 的数据库,在该库中有一个 TABLES 表,这个表主要字段分别是:

TABLE_SCHEMA : 数据库名

TABLE_NAME:表名

ENGINE:所使用的存储引擎

TABLES_ROWS:记录数

DATA_LENGTH:数据大小

INDEX_LENGTH:索引大小

下面的SQL语句给出了查询方法,同时也统计出了占用存储空间的信息:

复制代码
SELECT information_schema.`TABLES`.TABLE_NAME,
       (DATA_LENGTH/<strong>1024</strong>/<strong>1024</strong>) as DataM ,
    (INDEX_LENGTH/<strong>1024</strong>/<strong>1024</strong>) as IndexM, 
    ((DATA_LENGTH+INDEX_LENGTH)/<strong>1024</strong>/<strong>1024</strong>) as AllM,
    TABLE_ROWS
from information_schema.`TABLES` 
where information_schema.`TABLES`.TABLE_SCHEMA=&#39;abc&#39;;
复制代码
Statement:
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