13.7.5.37 SHOW TABLE STATUS Syntax

       


 

Press CTRL+C to copy

SHOW   TABLE   STATUS   [{   FROM   |   IN}   db_name   ]   [   LIKE   'pattern'   |   WHERE   expr   ]      

SHOW TABLE STATUS works likes SHOW TABLES, but provides a lot of information about each non-TEMPORARY table. You can also get this list using the mysqlshow --status db_name command. The LIKE clause, if present, indicates which table names to match. The WHERE clause can be given to select rows using more general conditions, as discussed in Section 21.33, “Extensions to SHOW Statements”.

This statement also displays information about views.

SHOW TABLE STATUS output has the following columns:

  • Name

    The name of the table.

  • Engine

    The storage engine for the table. See Chapter 15, Alternative Storage Engines.

  • Version

    The version number of the table's .frm file.

  • Row_format

    The row-storage format (Fixed, Dynamic, Compressed, Redundant, Compact). For MyISAM tables, Dynamic corresponds to what myisamchk -dvv reports as Packed. InnoDB table format is either Redundant or Compact when using the Antelope file format, or Compressed or Dynamic when using the Barracuda file format.

  • Rows

    The number of rows. Some storage engines, such as MyISAM, store the exact count. For other storage engines, such as InnoDB, this value is an approximation, and may vary from the actual value by as much as 40 to 50%. In such cases, use SELECT COUNT(*) to obtain an accurate count.

    The Rows value is NULL for tables in the INFORMATION_SCHEMA database.

  • Avg_row_length

    The average row length.

    Refer to the notes at the end of this section for related information.

  • Data_length

    For MyISAM, Data_length is the length of the data file, in bytes.

    For InnoDB, Data_length is the approximate amount of memory allocated for the clustered index, in bytes. Specifically, it is the clustered index size, in pages, multiplied by the InnoDB page size.

    Refer to the notes at the end of this section for information regarding other storage engines.

  • Max_data_length

    For MyISAM, Max_data_length is maximum length of the data file. This is the total number of bytes of data that can be stored in the table, given the data pointer size used.

    Unused for InnoDB.

    Refer to the notes at the end of this section for information regarding other storage engines.

  • Index_length

    For MyISAM, Index_length is the length of the index file, in bytes.

    For InnoDB, Index_length is the approximate amount of memory allocated for non-clustered indexes, in bytes. Specifically, it is the sum of non-clustered index sizes, in pages, multiplied by the InnoDB page size.

    Refer to the notes at the end of this section for information regarding other storage engines.

  • Data_free

    The number of allocated but unused bytes.

    This information is also shown for InnoDB tables (previously, it was in the Comment value). InnoDB tables report the free space of the tablespace to which the table belongs. For a table located in the shared tablespace, this is the free space of the shared tablespace. If you are using multiple tablespaces and the table has its own tablespace, the free space is for only that table. Free space means the number of bytes in completely free extents minus a safety margin. Even if free space displays as 0, it may be possible to insert rows as long as new extents need not be allocated.

    For partitioned tables, this value is only an estimate and may not be absolutely correct. A more accurate method of obtaining this information in such cases is to query the INFORMATION_SCHEMA.PARTITIONS table, as shown in this example:


     

    Press CTRL+C to copy

         

    SELECT      SUM  (DATA_FREE      )      FROM INFORMATION_SCHEMA      .  PARTITIONS      WHERE TABLE_SCHEMA      =      'mydb'      AND      TABLE_NAME      =      'mytable'  ;      

    For more information, see Section 21.13, “The INFORMATION_SCHEMA PARTITIONS Table”.

  • Auto_increment

    The next AUTO_INCREMENT value.

  • Create_time

    When the table was created.

  • Update_time

    When the data file was last updated. For some storage engines, this value is NULL. For example, InnoDB stores multiple tables in its system tablespace and the data file timestamp does not apply. Even with file-per-table mode with each InnoDB table in a separate .ibd file, change buffering can delay the write to the data file, so the file modification time is different from the time of the last insert, update, or delete. For MyISAM, the data file timestamp is used; however, on Windows the timestamp is not updated by updates so the value is inaccurate.

  • Check_time

    When the table was last checked. Not all storage engines update this time, in which case the value is always NULL.

  • Collation

    The table's character set and collation.

  • Checksum

    The live checksum value (if any).

  • Create_options

    Extra options used with CREATE TABLE. The original options supplied when CREATE TABLE is called are retained and the options reported here may differ from the active table settings and options.

  • Comment

    The comment used when creating the table (or information as to why MySQL could not access the table information).

Notes:

  • For MEMORY tables, the Data_length, Max_data_length, and Index_length values approximate the actual amount of allocated memory. The allocation algorithm reserves memory in large amounts to reduce the number of allocation operations.

  • For NDB tables, the output of this statement shows appropriate values for the Avg_row_length and Data_length columns, with the exception that BLOB columns are not taken into account

  • For views, all the fields displayed by SHOW TABLE STATUS are NULL except that Name indicates the view name and Comment says view. 





[FROM db_name]  可选,表示查询哪个数据库下面的表信息。

[LIKE 'pattern'] 可选,表示查询哪些具体的表名。


2、例如


(1)、show table status from db_name 

查询db_name 数据库里所有表的信息


(2)、show table status from db_name like 'esf_seller_history'\G;

查询db_name 里 esf_seller_history 表的信息


(3)、show table status from db_name LIKE 'uc%'

查询db_name 数据库里表名以uc开头的表的信息


MySQL之SHOW TABLE STATUS命令_MySQL

show table status 获取表的信息

show table status like 'tableName' \G

1.Name  

       表名称

2.Engine:

       表的存储引擎

3.Version:

       版本

4.Row_format

       行格式。对于MyISAM引擎,这可能是Dynamic,Fixed或Compressed。动态行的行长度可变,例如Varchar或Blob类型字段。固定行是指行长度不变,例如Char和Integer类型字段。

5. Rows

       表中的行数。对于非事务性表,这个值是精确的,对于事务性引擎,这个值通常是估算的。

6.Avg_row_length

       平均每行包括的字节数 

7.Data_length

       整个表的数据量(单位:字节)

8.Max_data_length

      表可以容纳的最大数据量

9.Index_length

      索引占用磁盘的空间大小 

10.Data_free

     对于MyISAM引擎,标识已分配,但现在未使用的空间,并且包含了已被删除行的空间。

11.Auto_increment

     下一个Auto_increment的值

12.Create_time

     表的创建时间

13.Update_time

     表的最近更新时间

14.Check_time

     使用 check table 或myisamchk工具检查表的最近时间

15.Collation

     表的默认字符集和字符排序规则

16.Checksum

如果启用,则对整个表的内容计算时的校验和
17.Create_options

指表创建时的其他所有选项

18.Comment

包含了其他额外信息,对于MyISAM引擎,包含了注释徐标新,如果表使用的是innodb引擎 ,将现实表的剩余空间。如果是一个视图,注释里面包含了VIEW字样。

SHOW TABLE STATUS会返回以下字段:

Name

表的名称

Engine

表的存储引擎。在MySQL 4.1.2之前,本值被标记为Type。

Version

表的.frm文件的版本号

Row_format

行存储格式(Fixed, Dynamic, Compressed, Redundant, Compact)。InnoDB表的格式被报告为Redundant或Compact

Rows

行的数目。部分存储引擎,如MyISAM,存储精确的数目。对于其它存储引擎,比如InnoDB,本值是一个大约的数,与实际值相差可达40到50%。在这些情况下,使用SELECT COUNT(*)来获得准确的数目。对于在INFORMATION_SCHEMA数据库中的表,Rows值为NULL。

Avg_row_length

平均的行长度。

 

Data_length

数据文件的长度。

Max_data_length

数据文件的最大长度。如果给定了数据指针的大小,这是可以被存储在表中的数据的字节总数。

 

Index_length

索引文件的长度。

Data_free

被整序,但是未使用的字节的数目。

Auto_increment

下一个AUTO_INCREMENT值。

Create_time

表创建时间。

Update_time

什么时候数据文件被最后一次更新

Check_time

什么时候表被最后一次检查。不是所有的存储引擎此时都更新,在此情况下,值为NULL。

Collation

表的字符集和整序。

Checksum

活性校验和值。

Create_options

和CREATE TABLE同时使用的额外选项。

Comment

创建表时使用的评注(或者有关为什么MySQL可以访问表信息的说明)。


 




1.首先,在myisam等一些不支持事务的引擎中,这个值是精确的,因为myisam会提供rows的精确存储  

2.而对于innodb这种事务的引擎中,由于不会存储精确的rows,它把表格的数据和索引都存储在/var/lib/mysql/ibdata*中,当运行这个语句的时候,他会从这个文件下采集一系列的数据进行推断从而得到行的近似数,所以innodb承认高达百分之五十使用这个语句的时候,行数都是不准确的。  

     从事务的角度出发对innodb这种情况进行分析的话,由于它提供事务服务,所以实际的行数取决于事务的隔离级别,由于不同的事务在不同的隔离级别运行,这就意味着只有当没有事务运行的时候才能够提供准确的数据,所以很难提供准确的行数。  

3.另外,对于在INFORMATION_SCHEMA数据库中的表,Rows值为NULL  

4.额外的收获:由于上述存储形式的关系,在myisam执行count(*)是很快的,因为它会直接取出rows中的值,而对于不提供rows精确存储的数据库表格来说,它会进行遍历,才能获得精确的count值,所以会慢一些  





给MYSQL的SHOW TABLE STATUS结果做过滤

MySQL中可以使用 show table status 查看表的状态,但是不能像select 语句选出结果那样做结果过滤。

有没有办法像select语句那样过滤呢,答案是有的,就是从information_schema库的tables表中查询。

如下是模仿show table status 的SQL:

SELECT table_name,Engine,Version,Row_format,table_rows,Avg_row_length,
  Data_length,Max_data_length,Index_length,Data_free,Auto_increment,
  Create_time,Update_time,Check_time,table_collation,Checksum,
  Create_options,table_comment
FROM information_schema.tables
WHERE Table_Schema='MyDataBaseName';

 

注意替换MyDataBaseName的名称为自己的库名称,这样就可以方便在Where部分添加各种条件过滤了。