information-schema - information_schema 数据库代表什么?

标签 information-schema mysql5

我在 mysql 中有一个数据库。

但是当我登录 phpMyAdmin 时,它显示了另一个名为 information_schema 的数据库。

该数据库是否始终与一个数据库一起存在?

我的意思是说 mysql 中存在的每个数据库都有一个 information_schema 的副本,还是每个 mysql 服务器都有一个名为 info_schema 的数据库?

如果我修改这个 information_schema 数据库,这将如何影响我当前的数据库?

最佳答案

您可以将 information_schema 视为“主数据库”,其中包含有关服务器上所有其他数据库的详细信息,例如表、列和用户的名称和类型。

什么是信息模式?

来自 the reference documentation:

INFORMATION_SCHEMA provides access to database metadata.

Metadata is data about the data, such as the name of a database or table, the data type of a column, or access privileges. Other terms that sometimes are used for this information are data dictionary and system catalog.

INFORMATION_SCHEMA is the information database, the place that stores information about all the other databases that the MySQL server maintains. Inside INFORMATION_SCHEMA there are several read-only tables. They are actually views, not base tables, so there are no files associated with them.



information_schema 中存储了什么?

您可以通过查看 this diagram 来查看 information_schema 中存储的事物种类以及它们的组织方式。 (对于 MySQL 5.0)或 this diagram (对于 MySQL 5.1)。

如果我修改 information_schema 会发生什么?

实际上,information_schema 是只读 View 的集合。因此,应该不可能对其进行修改并造成任何损坏。然而,the MySQL FAQ on this topic有话要说:

23.7.3: Can I add to or otherwise modify the tables found in the INFORMATION_SCHEMA database?

No. Since applications may rely on a certain standard structure, this should not be modified. For this reason, we cannot support bugs or other issues which result from modifying INFORMATION_SCHEMA tables or data.



这意味着,如果您确实发现自己能够修改 information_schema(这应该是不可能的,并且在 MySQL 中,但 SQL 的其他供应商实现可能允许),您至少应该选择不这样做。如果您可以损坏/修改 information_schema,您将损坏其他数据库的实际结构(例如表名、列类型)。

每个用户都有自己的 information_schema 副本吗?

每个用户都可以看到与他们有权访问的表和数据库相关的 information_schema。一些权限非常有限的用户仍会看到 information_schema,但对于任何 information_schema 查询只会看到 NULL 值。但是,重要的是要记住,information_schema 不是实际的数据库,而只是 SQL 提供的一种方便的方式,以便您可以选择有关数据库和表的信息。

来自 the reference documentation:

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 will see NULL.



我在哪里可以找到更多信息?
  • MySQL 引用手册关于 information_schema 的文章 ( http://dev.mysql.com/doc/refman/5.0/en/information-schema.html )
  • 关于信息架构的 MySQL 常见问题文章 ( http://dev.mysql.com/doc/refman/5.0/en/faqs-information-schema.html )
  • 关于information-schema - information_schema 数据库代表什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3050225/

    相关文章:

    mysql - 如何访问MySql数据字典?

    mysql - 如何修复 `information_schema` .`TABLES` ?

    mysql - MariaDB/MySQL : Get checksum of InnoDB table

    mysql - 使用多个 LIKE 语句和 REGEXP 的查询可以更有效吗?

    mysql - 使用 MySQL 生成按货币分组的填补空白的每日销售报告

    mysql - 当列数据发生变化时如何获取行

    MySQL 性能 : Single table or multiple tables

    mysql - 为什么 information_schema.tables 对行数给出如此不稳定的答案?

    mysql - SQL 检索列信息(包括引用)

    mysql - MySQL中的表名区分大小写吗?