Chapter 20. The INFORMATION_SCHEMA Database

MySQL 5.0

Chapter 20. The INFORMATION_SCHEMA Database

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.

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

In effect, we have a database named , although the server does not create a database directory with that name. It is possible to select as the default database with a statement, but it is possible only to read the contents of tables. You cannot insert into them, update them, or delete from them.

Here is an example of a statement that retrieves information from :

mysql> 
    -> 
    -> 
    -> 
+------------+------------+--------+
| table_name | table_type | engine |
+------------+------------+--------+
| v56        | VIEW       | NULL   |
| v3         | VIEW       | NULL   |
| v2         | VIEW       | NULL   |
| v          | VIEW       | NULL   |
| tables     | BASE TABLE | MyISAM |
| t7         | BASE TABLE | MyISAM |
| t3         | BASE TABLE | MyISAM |
| t2         | BASE TABLE | MyISAM |
| t          | BASE TABLE | MyISAM |
| pk         | BASE TABLE | InnoDB |
| loop       | BASE TABLE | MyISAM |
| kurs       | BASE TABLE | MyISAM |
| k          | BASE TABLE | MyISAM |
| into       | BASE TABLE | MyISAM |
| goto       | BASE TABLE | MyISAM |
| fk2        | BASE TABLE | InnoDB |
| fk         | BASE TABLE | InnoDB |
+------------+------------+--------+
17 rows in set (0.01 sec)

Explanation: The statement requests a list of all the tables in database , in reverse alphabetical order, showing just three pieces of information: the name of the table, its type, and its storage engine.

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.

The statement is intended as a more consistent way to provide access to the information provided by the various statements that MySQL supports (, , and so forth). Using has these advantages, compared to :

  • It conforms to Codd's rules. That is, all access is done on tables.

  • Nobody needs to learn a new statement syntax. Because they already know how works, they only need to learn the object names.

  • The implementor need not worry about adding keywords.

  • There are millions of possible output variations, instead of just one. This provides more flexibility for applications that have varying requirements about what metadata they need.

  • Migration is easier because every other DBMS does it this way.

However, because is popular with MySQL employees and users, and because it might be confusing were it to disappear, the advantages of conventional syntax are not a sufficient reason to eliminate . In fact, along with the implementation of , there are enhancements to as well. These are described in Section 20.18, “Extensions to Statements”.

There is no difference between the privileges required for statements and those required to select information from . In either case, you have to have some privilege on an object in order to see information about it.

The implementation for the 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 column is the column in the table.

Although other DBMSs use a variety of names, like or , the standard name is .

The following sections describe each of the tables and columns that are in . For each column, there are three pieces of information:

  • Name” indicates the name for the column in the table. This corresponds to the standard SQL name unless the “Remarks” field says “MySQL extension.

  • Name” indicates the equivalent field name in the closest statement, if there is one.

  • Remarks” provides additional information where applicable. If this field is , it means that the value of the column is always . If this field says “MySQL extension,” the column is a MySQL extension to standard SQL.

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 to in the table.) See the list of reserved words near the end of this article: http://www.dbazine.com/gulutzan5.shtml.

The definition for character columns (for example, ) is generally ) CHARACTER SET utf8 where is at least 64.

Each section indicates what statement is equivalent to a that retrieves information from , if there is such a statement.

Note: At present, there are some missing columns and some columns out of order. We are working on this and update the documentation as changes are made.

20.1. The INFORMATION_SCHEMA SCHEMATA Table

A schema is a database, so the table provides information about databases.

Name Name Remarks
 
  Database
   
   
 

Notes:

  • was added in MySQL 5.0.6.

The following statements are equivalent:

SELECT SCHEMA_NAME AS `Database`
  FROM INFORMATION_SCHEMA.SCHEMATA
  [WHERE SCHEMA_NAME LIKE '']

SHOW DATABASES
  [LIKE '']