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. INFORMATION_SCHEMA
提供对数据库元数据的访问、有关MySQL服务器的信息,例如数据库或表的名称、列的数据类型或访问权限。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. INFORMATION_SCHEMA
是每个MySQL实例中的一个数据库,存储MySQL服务器维护的所有其他数据库的信息。The INFORMATION_SCHEMA
database contains several read-only tables. INFORMATION_SCHEMA
数据库包含几个只读表。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.USE
语句选择INFORMATION_SCHEMA
作为默认数据库,但只能读取表的内容,不能对表执行INSERT
、UPDATE
或DELETE
操作。
Here is an example of a statement that retrieves information from 下面是一个从INFORMATION_SCHEMA
:INFORMATION_SCHEMA
中检索信息的语句示例:
mysql>SELECT table_name, table_type, engine
FROM information_schema.tables
WHERE table_schema = 'db5'
ORDER BY table_name;
+------------+------------+--------+ | table_name | table_type | engine | +------------+------------+--------+ | fk | BASE TABLE | InnoDB | | fk2 | BASE TABLE | InnoDB | | goto | BASE TABLE | MyISAM | | into | BASE TABLE | MyISAM | | k | BASE TABLE | MyISAM | | kurs | BASE TABLE | MyISAM | | loop | BASE TABLE | MyISAM | | pk | BASE TABLE | InnoDB | | t | BASE TABLE | MyISAM | | t2 | BASE TABLE | MyISAM | | t3 | BASE TABLE | MyISAM | | t7 | BASE TABLE | MyISAM | | tables | BASE TABLE | MyISAM | | v | VIEW | NULL | | v2 | VIEW | NULL | | v3 | VIEW | NULL | | v56 | VIEW | NULL | +------------+------------+--------+ 17 rows in set (0.01 sec)
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.db5
中所有表的列表,只显示三条信息:表的名称、类型和存储引擎。
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 由于某些MySQL对象表示为文件,因此在INFORMATION_SCHEMA
string columns can be affected by file system case sensitivity. INFORMATION_SCHEMA
字符串列中的搜索可能会受到文件系统大小写敏感度的影响。For more information, see Section 10.8.7, “Using Collation in INFORMATION_SCHEMA Searches”.有关更多信息,请参阅第10.8.7节,“在INFORMATION_SCHEMA搜索中使用排序规则”。
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.它符合Codd的规则,因为所有的访问都是在表上完成的。
You can use the familiar syntax of the 您可以使用熟悉的SELECT
statement, and only need to learn some table and column names.SELECT
语句语法,只需要了解一些表名和列名。
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.INFORMATION_SCHEMA
查询的结果转换为应用程序所需的任何格式,例如要解析的数据结构或文本表示。
This technique is more interoperable with other database systems. 这种技术与其他数据库系统更具互操作性。For example, Oracle Database users are familiar with querying tables in the Oracle data dictionary.例如,Oracle数据库用户熟悉在Oracle数据字典中查询表。
Because 由于SHOW
is familiar and widely used, the SHOW
statements remain as an alternative. SHOW
是一个熟悉且广泛使用的节目,SHOW
语句仍然是一个替代方案。In fact, along with the implementation of INFORMATION_SCHEMA
, there are enhancements to SHOW
as described in Section 26.8, “Extensions to SHOW Statements”.
For most 对于大多数INFORMATION_SCHEMA
tables, each MySQL user has the right to access them, but can see only the rows in the tables that correspond to objects for which the user has the proper access privileges. INFORMATION_SCHEMA
,每个MySQL用户都有权访问这些表,但只能看到表中与用户具有适当访问权限的对象对应的行。In some cases (for example, the ROUTINE_DEFINITION
column in the INFORMATION_SCHEMA
ROUTINES
table), users who have insufficient privileges see NULL
. Some tables have different privilege requirements; for these, the requirements are mentioned in the applicable table descriptions. For example, InnoDB
tables (tables with names that begin with INNODB_
) require 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. INFORMATION_SCHEMA
查询可能需要很长时间,并会影响性能。To check the efficiency of a query, you can use 要检查查询的效率,可以使用EXPLAIN
. EXPLAIN
。For information about using 有关使用EXPLAIN
output to tune INFORMATION_SCHEMA
queries, see Section 8.2.3, “Optimizing INFORMATION_SCHEMA Queries”.EXPLAIN
输出优化INFORMATION_SCHEMA
查询的信息,请参阅第8.2.3节,“优化INFORMATION_SCHEMA查询”。
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. SQL Server 2000(也遵循该标准)的用户可能会注意到一种强烈的相似性。However, MySQL has omitted many columns that are not relevant for our implementation, and added columns that are MySQL-specific. 然而,MySQL省略了许多与实现无关的列,并添加了特定于MySQL的列。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
. INFORMATION_SCHEMA
中的每个表和列。For each column, there are three pieces of information:对于每一列,有三条信息:
“INFORMATION_SCHEMA
Name” indicates the name for the column in the INFORMATION_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 closest SHOW
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 always NULL
. 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_SCHEMA
相关的其他内容:
information about INFORMATION_SCHEMA
tables specific to the InnoDB
storage engine: Section 26.4, “INFORMATION_SCHEMA InnoDB Tables”
information about INFORMATION_SCHEMA
tables specific to the thread pool plugin: Section 26.5, “INFORMATION_SCHEMA Thread Pool Tables”
information about 关于特定于连接控制插件的INFORMATION_SCHEMA
tables specific to the CONNECTION_CONTROL
plugin: Section 26.6, “INFORMATION_SCHEMA Connection-Control Tables”INFORMATION_SCHEMA
表的信息:第26.6节,“信息模式连接控制表”。
Answers to questions that are often asked concerning the 关于INFORMATION_SCHEMA
database: Section A.7, “MySQL 8.0 FAQ: INFORMATION_SCHEMA”INFORMATION_SCHEMA
数据库的常见问题解答:A.7节,“MySQL 8.0常见问题解答:INFORMATION_SCHEMA”
INFORMATION_SCHEMA
queries and the optimizer: Section 8.2.3, “Optimizing INFORMATION_SCHEMA Queries”查询和优化器:第8.2.3节,“优化INFORMATION_SCHEMA查询”。
The effect of collation on 排序规则对INFORMATION_SCHEMA
comparisons: Section 10.8.7, “Using Collation in INFORMATION_SCHEMA Searches”INFORMATION_SCHEMA
比较的影响:第10.8.7节,“在信息模式搜索中使用排序规则”。