Mysql:Information_schema:信息构架 or 数据字典 or 系统目录
INFORMATION_SCHEMA
provides access to database metadata, information about the MySQL server such as the name of a database or table, the data type of a column, or access privileges. Other terms that are sometimes used for this information are data dictionary and system catalog.
INFORMATION_SCHEMA
provides access to database metadata, information about the MySQL server such as the name of a database or table, the data type of a column, or access privileges. Other terms that are sometimes used for this information are data dictionary and system catalog.
INFORMATION_SCHEMA
is a database within each MySQL instance, the place that stores information about all the other databases that the MySQL server maintains. The INFORMATION_SCHEMA
database contains several read-only tables. They are actually views, not base tables, so there are no files associated with them, and you cannot set triggers on them. Also, there is no database directory with that name.
Although you can select INFORMATION_SCHEMA
as the default database with a USE
statement, you can only read the contents of tables, not perform INSERT
, UPDATE
, or DELETE
operations on them.
Here is an example of a statement that retrieves information from INFORMATION_SCHEMA
:
SELECT table_name, table_type, engine FROM information_schema.tables WHERE table_schema = 'db5' ORDER BY table_name;
Explanation: The statement requests a list of all the tables in database db5
, showing just three pieces of information: the name of the table, its type, and its storage engine.
The definition for character columns (for example, TABLES.TABLE_NAME
) is generally VARCHAR(
where N
) CHARACTER SET utf8N
is at least 64. MySQL uses the default collation for this character set (utf8_general_ci
) for all searches, sorts, comparisons, and other string operations on such columns.
Because some MySQL objects are represented as files, searches in INFORMATION_SCHEMA
string columns can be affected by file system case sensitivity. For more information, see Section 10.8.7, “Using Collation in INFORMATION_SCHEMA Searches”.
The SELECT ... FROM INFORMATION_SCHEMA
statement is intended as a more consistent way to provide access to the information provided by the various SHOW
statements that MySQL supports (SHOW DATABASES
, SHOW TABLES
, and so forth). Using SELECT
has these advantages, compared to SHOW
:
-
It conforms to Codd's rules, because all access is done on tables.
-
You can use the familiar syntax of the
SELECT
statement, and only need to learn some table and column names. -
The implementor need not worry about adding keywords.
-
You can filter, sort, concatenate, and transform the results from
INFORMATION_SCHEMA
queries into whatever format your application needs, such as a data structure or a text representation to parse. -
This technique is more interoperable with other database systems. For example, Oracle Database users are familiar with querying tables in the Oracle data dictionary.
Because SHOW
is familiar and widely used, the SHOW
statements remain as an alternative. In fact, along with the implementation of INFORMATION_SCHEMA
, there are enhancements to SHOW
as described in Section 25.48, “Extensions to SHOW Statements”.
Each MySQL user has the right to access these tables, but can see only the rows in the tables that correspond to objects for which the user has the proper access privileges. In some cases (for example, the ROUTINE_DEFINITION
column in the INFORMATION_SCHEMA
ROUTINES
table), users who have insufficient privileges see NULL
. These restrictions do not apply for InnoDB
tables; you can see them with only the PROCESS
privilege.
The same privileges apply to selecting information from INFORMATION_SCHEMA
and viewing the same information through SHOW
statements. In either case, you must have some privilege on an object to see information about it.
INFORMATION_SCHEMA
queries that search for information from more than one database might take a long time and impact performance. To check the efficiency of a query, you can use EXPLAIN
. For information about using EXPLAIN
output to tune INFORMATION_SCHEMA
queries, see Section 8.2.3, “Optimizing INFORMATION_SCHEMA Queries”.
The implementation for the INFORMATION_SCHEMA
table structures in MySQL follows the ANSI/ISO SQL:2003 standard Part 11 Schemata. Our intent is approximate compliance with SQL:2003 core feature F021 Basic information schema.
Users of SQL Server 2000 (which also follows the standard) may notice a strong similarity. However, MySQL has omitted many columns that are not relevant for our implementation, and added columns that are MySQL-specific. One such added column is the ENGINE
column in the INFORMATION_SCHEMA
TABLES
table.
Although other DBMSs use a variety of names, like syscat
or system
, the standard name is INFORMATION_SCHEMA
.
To avoid using any name that is reserved in the standard or in DB2, SQL Server, or Oracle, we changed the names of some columns marked “MySQL extension”. (For example, we changed COLLATION
to TABLE_COLLATION
in the TABLES
table.) See the list of reserved words near the end of this article: https://web.archive.org/web/20070428032454/http://www.dbazine.com/db2/db2-disarticles/gulutzan5.
The following sections describe each of the tables and columns in INFORMATION_SCHEMA
. For each column, there are three pieces of information:
-
“
INFORMATION_SCHEMA
Name” indicates the name for the column in theINFORMATION_SCHEMA
table. This corresponds to the standard SQL name unless the “Remarks” field says “MySQL extension.” -
“
SHOW
Name” indicates the equivalent field name in the closestSHOW
statement, if there is one. -
“Remarks” provides additional information where applicable. If this field is
NULL
, it means that the value of the column is alwaysNULL
. If this field says “MySQL extension,” the column is a MySQL extension to standard SQL.
Many sections indicate what SHOW
statement is equivalent to a SELECT
that retrieves information from INFORMATION_SCHEMA
. For SHOW
statements that display information for the default database if you omit a FROM
clause, you can often select information for the default database by adding an db_name
AND TABLE_SCHEMA = SCHEMA()
condition to the WHERE
clause of a query that retrieves information from an INFORMATION_SCHEMA
table.
These sections discuss additional INFORMATION_SCHEMA
-related topics:
-
information about
INFORMATION_SCHEMA
tables specific to theInnoDB
storage engine: Section 25.45, “INFORMATION_SCHEMA InnoDB Tables” -
information about
INFORMATION_SCHEMA
tables specific to the thread pool plugin: Section 25.46, “INFORMATION_SCHEMA Thread Pool Tables” -
information about
INFORMATION_SCHEMA
tables specific to theCONNECTION_CONTROL
plugin: Section 25.47, “INFORMATION_SCHEMA Connection-Control Tables” -
Answers to questions that are often asked concerning the
INFORMATION_SCHEMA
database: Section A.7, “MySQL 8.0 FAQ: INFORMATION_SCHEMA” -
INFORMATION_SCHEMA
queries and the optimizer: Section 8.2.3, “Optimizing INFORMATION_SCHEMA Queries” -
The effect of collation on
INFORMATION_SCHEMA
comparisons: Section 10.8.7, “Using Collation in INFORMATION_SCHEMA Searches”
Table of Contents
- 25.1 Introduction
- 25.2 The INFORMATION_SCHEMA ADMINISTRABLE_ROLE_AUTHORIZATIONS Table
- 25.3 The INFORMATION_SCHEMA APPLICABLE_ROLES Table
- 25.4 The INFORMATION_SCHEMA CHARACTER_SETS Table
- 25.5 The INFORMATION_SCHEMA CHECK_CONSTRAINTS Table
- 25.6 The INFORMATION_SCHEMA COLLATIONS Table
- 25.7 The INFORMATION_SCHEMA COLLATION_CHARACTER_SET_APPLICABILITY Table
- 25.8 The INFORMATION_SCHEMA COLUMNS Table
- 25.9 The INFORMATION_SCHEMA COLUMN_PRIVILEGES Table
- 25.10 The INFORMATION_SCHEMA COLUMN_STATISTICS Table
- 25.11 The INFORMATION_SCHEMA ENABLED_ROLES Table
- 25.12 The INFORMATION_SCHEMA ENGINES Table
- 25.13 The INFORMATION_SCHEMA EVENTS Table
- 25.14 The INFORMATION_SCHEMA FILES Table
- 25.15 The INFORMATION_SCHEMA KEY_COLUMN_USAGE Table
- 25.16 The INFORMATION_SCHEMA ndb_transid_mysql_connection_map Table
- 25.17 The INFORMATION_SCHEMA KEYWORDS Table
- 25.18 The INFORMATION_SCHEMA OPTIMIZER_TRACE Table
- 25.19 The INFORMATION_SCHEMA PARAMETERS Table
- 25.20 The INFORMATION_SCHEMA PARTITIONS Table
- 25.21 The INFORMATION_SCHEMA PLUGINS Table
- 25.22 The INFORMATION_SCHEMA PROCESSLIST Table
- 25.23 The INFORMATION_SCHEMA PROFILING Table
- 25.24 The INFORMATION_SCHEMA REFERENTIAL_CONSTRAINTS Table
- 25.25 The INFORMATION_SCHEMA RESOURCE_GROUPS Table
- 25.26 The INFORMATION_SCHEMA ROLE_COLUMN_GRANTS Table
- 25.27 The INFORMATION_SCHEMA ROLE_ROUTINE_GRANTS Table
- 25.28 The INFORMATION_SCHEMA ROLE_TABLE_GRANTS Table
- 25.29 The INFORMATION_SCHEMA ROUTINES Table
- 25.30 The INFORMATION_SCHEMA SCHEMATA Table
- 25.31 The INFORMATION_SCHEMA SCHEMA_PRIVILEGES Table
- 25.32 The INFORMATION_SCHEMA STATISTICS Table
- 25.33 The INFORMATION_SCHEMA ST_GEOMETRY_COLUMNS Table
- 25.34 The INFORMATION_SCHEMA ST_SPATIAL_REFERENCE_SYSTEMS Table
- 25.35 The INFORMATION_SCHEMA ST_UNITS_OF_MEASURE Table
- 25.36 The INFORMATION_SCHEMA TABLES Table
- 25.37 The INFORMATION_SCHEMA TABLESPACES Table
- 25.38 The INFORMATION_SCHEMA TABLE_CONSTRAINTS Table
- 25.39 The INFORMATION_SCHEMA TABLE_PRIVILEGES Table
- 25.40 The INFORMATION_SCHEMA TRIGGERS Table
- 25.41 The INFORMATION_SCHEMA USER_PRIVILEGES Table
- 25.42 The INFORMATION_SCHEMA VIEWS Table
- 25.43 The INFORMATION_SCHEMA VIEW_ROUTINE_USAGE Table
- 25.44 The INFORMATION_SCHEMA VIEW_TABLE_USAGE Table
- 25.45 INFORMATION_SCHEMA InnoDB Tables
- 25.45.1 The INFORMATION_SCHEMA INNODB_BUFFER_PAGE Table
- 25.45.2 The INFORMATION_SCHEMA INNODB_BUFFER_PAGE_LRU Table
- 25.45.3 The INFORMATION_SCHEMA INNODB_BUFFER_POOL_STATS Table
- 25.45.4 The INFORMATION_SCHEMA INNODB_CACHED_INDEXES Table
- 25.45.5 The INFORMATION_SCHEMA INNODB_CMP and INNODB_CMP_RESET Tables
- 25.45.6 The INFORMATION_SCHEMA INNODB_CMPMEM and INNODB_CMPMEM_RESET Tables
- 25.45.7 The INFORMATION_SCHEMA INNODB_CMP_PER_INDEX and INNODB_CMP_PER_INDEX_RESET Tables
- 25.45.8 The INFORMATION_SCHEMA INNODB_COLUMNS Table
- 25.45.9 The INFORMATION_SCHEMA INNODB_DATAFILES Table
- 25.45.10 The INFORMATION_SCHEMA INNODB_FIELDS Table
- 25.45.11 The INFORMATION_SCHEMA INNODB_FOREIGN Table
- 25.45.12 The INFORMATION_SCHEMA INNODB_FOREIGN_COLS Table
- 25.45.13 The INFORMATION_SCHEMA INNODB_FT_BEING_DELETED Table
- 25.45.14 The INFORMATION_SCHEMA INNODB_FT_CONFIG Table
- 25.45.15 The INFORMATION_SCHEMA INNODB_FT_DEFAULT_STOPWORD Table
- 25.45.16 The INFORMATION_SCHEMA INNODB_FT_DELETED Table
- 25.45.17 The INFORMATION_SCHEMA INNODB_FT_INDEX_CACHE Table
- 25.45.18 The INFORMATION_SCHEMA INNODB_FT_INDEX_TABLE Table
- 25.45.19 The INFORMATION_SCHEMA INNODB_INDEXES Table
- 25.45.20 The INFORMATION_SCHEMA INNODB_LOCKS Table
- 25.45.21 The INFORMATION_SCHEMA INNODB_LOCK_WAITS Table
- 25.45.22 The INFORMATION_SCHEMA INNODB_METRICS Table
- 25.45.23 The INFORMATION_SCHEMA INNODB_SESSION_TEMP_TABLESPACES Table
- 25.45.24 The INFORMATION_SCHEMA INNODB_TABLES Table
- 25.45.25 The INFORMATION_SCHEMA INNODB_TABLESPACES Table
- 25.45.26 The INFORMATION_SCHEMA INNODB_TABLESPACES_BRIEF Table
- 25.45.27 The INFORMATION_SCHEMA INNODB_TABLESTATS View
- 25.45.28 The INFORMATION_SCHEMA INNODB_TEMP_TABLE_INFO Table
- 25.45.29 The INFORMATION_SCHEMA INNODB_TRX Table
- 25.45.30 The INFORMATION_SCHEMA INNODB_VIRTUAL Table
- 25.46 INFORMATION_SCHEMA Thread Pool Tables
- 25.47 INFORMATION_SCHEMA Connection-Control Tables
- 25.48 Extensions to SHOW Statements
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
2009-03-16 Oracle学习笔记:oracle的启动过程