10bet网址
MySQL 8.0 Reference Manual
Related Documentation Download this Manual Excerpts from this Manual

26.3.38 The INFORMATION_SCHEMA TABLES Table

TheTABLEStable provides information about tables in databases.

Columns inTABLESthat represent table statistics hold cached values. Theinformation_schema_stats_expirysystem variable defines the period of time before cached table statistics expire. The default is 86400 seconds (24 hours). If there are no cached statistics or statistics have expired, statistics are retrieved from storage engines when querying table statistics columns. To update cached values at any time for a given table, useANALYZE TABLE. To always retrieve the latest statistics directly from storage engines, setinformation_schema_stats_expiryto0. For more information, seeSection 8.2.3, “Optimizing INFORMATION_SCHEMA Queries”.

Note

If theinnodb_read_onlysystem variable is enabled,ANALYZE TABLEmay fail because it cannot update statistics tables in the data dictionary, which useInnoDB. ForANALYZE TABLEoperations that update the key distribution, failure may occur even if the operation updates the table itself (for example, if it is aMyISAM表)。获得更新的集权的分布ics, setinformation_schema_stats_expiry=0.

TheTABLEStable has these columns:

  • TABLE_CATALOG

    The name of the catalog to which the table belongs. This value is alwaysdef.

  • TABLE_SCHEMA

    The name of the schema (database) to which the table belongs.

  • TABLE_NAME

    The name of the table.

  • TABLE_TYPE

    BASE TABLEfor a table,VIEWfor a view, orSYSTEM VIEWfor anINFORMATION_SCHEMAtable.

    TheTABLEStable does not listTEMPORARYtables.

  • ENGINE

    The storage engine for the table. SeeChapter 15,The InnoDB Storage Engine, andChapter 16,Alternative Storage Engines.

    For partitioned tables,ENGINEshows the name of the storage engine used by all partitions.

  • VERSION

    This column is unused. With the removal of.frmfiles in MySQL 8.0, this column now reports a hardcoded value of10, which is the last.frmfile version used in MySQL 5.7.

  • ROW_FORMAT

    The row-storage format (Fixed,Dynamic,Compressed,Redundant,Compact). ForMyISAMtables,Dynamiccorresponds to whatmyisamchk -dvvreports asPacked.

  • TABLE_ROWS

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

    TABLE_ROWSisNULLforINFORMATION_SCHEMAtables.

    ForInnoDBtables, the row count is only a rough estimate used in SQL optimization. (This is also true if theInnoDBtable is partitioned.)

  • AVG_ROW_LENGTH

    The average row length.

  • DATA_LENGTH

    ForMyISAM,DATA_LENGTHis the length of the data file, in bytes.

    ForInnoDB,DATA_LENGTHis the approximate amount of space allocated for the clustered index, in bytes. Specifically, it is the clustered index size, in pages, multiplied by theInnoDBpage size.

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

  • MAX_DATA_LENGTH

    ForMyISAM,MAX_DATA_LENGTHis 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 forInnoDB.

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

  • INDEX_LENGTH

    ForMyISAM,INDEX_LENGTHis the length of the index file, in bytes.

    ForInnoDB,INDEX_LENGTHis the approximate amount of space allocated for non-clustered indexes, in bytes. Specifically, it is the sum of non-clustered index sizes, in pages, multiplied by theInnoDBpage 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.

    InnoDBtables 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 NDB Cluster,DATA_FREE显示磁盘上的空间分配,但不使用d by, a Disk Data table or fragment on disk. (In-memory data resource usage is reported by theDATA_LENGTHcolumn.)

    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 theINFORMATION_SCHEMAPARTITIONStable, as shown in this example:

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

    For more information, seeSection 26.3.21, “The INFORMATION_SCHEMA PARTITIONS Table”.

  • AUTO_INCREMENT

    The nextAUTO_INCREMENTvalue.

  • CREATE_TIME

    When the table was created.

  • UPDATE_TIME

    When the data file was last updated. For some storage engines, this value isNULL. For example,InnoDBstores multiple tables in itssystem tablespaceand the data file timestamp does not apply. Even withfile-per-tablemode with eachInnoDBtable in a separate.ibdfile,change bufferingcan delay the write to the data file, so the file modification time is different from the time of the last insert, update, or delete. ForMyISAM, the data file timestamp is used; however, on Windows the timestamp is not updated by updates, so the value is inaccurate.

    UPDATE_TIMEdisplays a timestamp value for the lastUPDATE,INSERT, orDELETEperformed onInnoDBtables that are not partitioned. For MVCC, the timestamp value reflects theCOMMITtime, which is considered the last update time. Timestamps are not persisted when the server is restarted or when the table is evicted from theInnoDB数据字典缓存。

  • CHECK_TIME

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

    For partitionedInnoDBtables,CHECK_TIMEis alwaysNULL.

  • TABLE_COLLATION

    The table default collation. The output does not explicitly list the table default character set, but the collation name begins with the character set name.

  • CHECKSUM

    The live checksum value, if any.

  • CREATE_OPTIONS

    Extra options used withCREATE TABLE.

    CREATE_OPTIONSshowspartitionedfor a partitioned table.

    Prior to MySQL 8.0.16,CREATE_OPTIONSshows theENCRYPTIONclause specified for tables created in file-per-table tablespaces. As of MySQL 8.0.16, it shows the encryption clause for file-per-table tablespaces if the table is encrypted or if the specified encryption differs from the schema encryption. The encryption clause is not shown for tables created in general tablespaces. To identify encrypted file-per-table and general tablespaces, query theINNODB_TABLESPACESENCRYPTIONcolumn.

    When creating a table withstrict modedisabled, the storage engine's default row format is used if the specified row format is not supported. The actual row format of the table is reported in theROW_FORMATcolumn.CREATE_OPTIONSshows the row format that was specified in theCREATE TABLEstatement.

    When altering the storage engine of a table, table options that are not applicable to the new storage engine are retained in the table definition to enable reverting the table with its previously defined options to the original storage engine, if necessary. TheCREATE_OPTIONScolumn may show retained options.

  • TABLE_COMMENT

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

Notes

  • ForNDBtables, the output of this statement shows appropriate values for theAVG_ROW_LENGTHandDATA_LENGTHcolumns, with the exception thatBLOBcolumns are not taken into account.

  • ForNDBtables,DATA_LENGTHincludes data stored in main memory only; theMAX_DATA_LENGTHandDATA_FREEcolumns apply to Disk Data.

  • For NDB Cluster Disk Data tables,MAX_DATA_LENGTHshows the space allocated for the disk part of a Disk Data table or fragment. (In-memory data resource usage is reported by theDATA_LENGTHcolumn.)

  • ForMEMORYtables, theDATA_LENGTH,MAX_DATA_LENGTH, andINDEX_LENGTHvalues approximate the actual amount of allocated memory. The allocation algorithm reserves memory in large amounts to reduce the number of allocation operations.

  • For views, mostTABLEScolumns are 0 orNULLexcept thatTABLE_NAMEindicates the view name,CREATE_TIMEindicates the creation time, andTABLE_COMMENTsaysVIEW.

Table information is also available from theSHOW TABLE STATUSandSHOW TABLESstatements. SeeSection 13.7.7.38, “SHOW TABLE STATUS Statement”, andSection 13.7.7.39, “SHOW TABLES Statement”. The following statements are equivalent:

选择TABLE_NAME、引擎版本、ROW_FORMAT助教BLE_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 = 'db_name' [AND table_name LIKE 'wild'] SHOW TABLE STATUS FROMdb_name[LIKE 'wild']

The following statements are equivalent:

SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'db_name' [AND table_name LIKE 'wild'] SHOW FULL TABLES FROMdb_name[LIKE 'wild']