INFORMATION_SCHEMA tables
The information_schema tables the front-ends serve, which ones have rows, and how they are generated.
information_schema is the catalog as MySQL and MariaDB show it. Its tables are virtual: they are generated from the front-end's own definitions of databases, tables, routines and triggers when a statement reads them, and nothing is stored. ORMs and tools read them to learn what exists. They usually ask about one schema and one table, so only the rows of the schemas and tables a WHERE names are produced (TABLE_SCHEMA = 'x' AND TABLE_NAME = 'y' is cheap).
Syntax#
SELECT ... FROM information_schema.table_name [WHERE ...]
USE information_schema;
SHOW TABLES FROM information_schema;Table and column names are upper case, as MySQL's, and are matched without regard to case.
Tables#
| Table | Rows | Notes |
|---|---|---|
SCHEMATA | the databases the account may see | CATALOG_NAME, SCHEMA_NAME, DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME, SQL_PATH, DEFAULT_ENCRYPTION |
TABLES | tables | 21 columns from TABLE_CATALOG to TABLE_COMMENT; sizes and TABLE_ROWS are 0 (no estimates) |
COLUMNS | columns of tables | COLUMN_TYPE, COLUMN_KEY, EXTRA, PRIVILEGES, GENERATION_EXPRESSION and the others of MySQL's table; hidden columns of functional indexes are left out |
STATISTICS | indexes | MySQL: IS_VISIBLE, EXPRESSION; MariaDB: IGNORED in their place. CARDINALITY is 0 |
TABLE_CONSTRAINTS | primary, unique, foreign key constraints | identical to MySQL for foreign keys (D64) |
KEY_COLUMN_USAGE | columns of keys and foreign keys | with REFERENCED_* columns |
REFERENTIAL_CONSTRAINTS | foreign keys | UPDATE_RULE, DELETE_RULE |
CHARACTER_SETS | the real list of the dialect | 41 rows for MySQL 9.7, 40 for MariaDB 11.4 |
COLLATIONS | the real list of the dialect | 286 rows for MySQL 9.7, 550 for MariaDB 11.4 |
ENGINES | one row | InnoDB |
ROUTINES | procedures and functions (D87) | the columns of MySQL's table |
TRIGGERS | triggers (D88) | the columns of MySQL's table |
VIEWS | none yet | columns exist, no rows |
EVENTS | none | there are no events |
PARTITIONS | none | there is no partitioning |
Remarks#
SHOW TABLES FROM information_schemalists these 15 tables.- Privileges: every account may read
information_schema, but only the rows of objects it has a privilege on are shown. - Not present:
CHECK_CONSTRAINTS,VIEWSrows,TABLES/COLUMNSrows for views,USER_PRIVILEGES,SCHEMA_PRIVILEGES,TABLE_PRIVILEGES,COLUMN_PRIVILEGES,PROCESSLIST,PARAMETERS,STATISTICSestimates,TABLESPACES,INNODB_*, and the system schemasmysql,performance_schemaandsys. - Row sets that are produced only for a named schema and table: a query without those conditions reads every database.
Examples#
Example:
SELECT INDEX_NAME, NON_UNIQUE, IS_VISIBLE
FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = 'iv1' AND TABLE_NAME = 't'
ORDER BY INDEX_NAME, SEQ_IN_INDEX;
SELECT COLUMN_NAME FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'fx1' AND TABLE_NAME = 't' ORDER BY ORDINAL_POSITION;
SELECT TRIGGER_NAME, EVENT_MANIPULATION, EVENT_OBJECT_TABLE, ACTION_TIMING, ACTION_ORDER
FROM information_schema.TRIGGERS WHERE TRIGGER_SCHEMA = 'm10c' ORDER BY TRIGGER_NAME;
SELECT schema_name, default_character_set_name, default_collation_name
FROM information_schema.schemata WHERE schema_name = 'db12';