SQL reference (MySQL and MariaDB dialects)

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#

SQL
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#

TableRowsNotes
SCHEMATAthe databases the account may seeCATALOG_NAME, SCHEMA_NAME, DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME, SQL_PATH, DEFAULT_ENCRYPTION
TABLEStables21 columns from TABLE_CATALOG to TABLE_COMMENT; sizes and TABLE_ROWS are 0 (no estimates)
COLUMNScolumns of tablesCOLUMN_TYPE, COLUMN_KEY, EXTRA, PRIVILEGES, GENERATION_EXPRESSION and the others of MySQL's table; hidden columns of functional indexes are left out
STATISTICSindexesMySQL: IS_VISIBLE, EXPRESSION; MariaDB: IGNORED in their place. CARDINALITY is 0
TABLE_CONSTRAINTSprimary, unique, foreign key constraintsidentical to MySQL for foreign keys (D64)
KEY_COLUMN_USAGEcolumns of keys and foreign keyswith REFERENCED_* columns
REFERENTIAL_CONSTRAINTSforeign keysUPDATE_RULE, DELETE_RULE
CHARACTER_SETSthe real list of the dialect41 rows for MySQL 9.7, 40 for MariaDB 11.4
COLLATIONSthe real list of the dialect286 rows for MySQL 9.7, 550 for MariaDB 11.4
ENGINESone rowInnoDB
ROUTINESprocedures and functions (D87)the columns of MySQL's table
TRIGGERStriggers (D88)the columns of MySQL's table
VIEWSnone yetcolumns exist, no rows
EVENTSnonethere are no events
PARTITIONSnonethere is no partitioning

Remarks#

  • SHOW TABLES FROM information_schema lists 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, VIEWS rows, TABLES / COLUMNS rows for views, USER_PRIVILEGES, SCHEMA_PRIVILEGES, TABLE_PRIVILEGES, COLUMN_PRIVILEGES, PROCESSLIST, PARAMETERS, STATISTICS estimates, TABLESPACES, INNODB_*, and the system schemas mysql, performance_schema and sys.
  • Row sets that are produced only for a named schema and table: a query without those conditions reads every database.

Examples#

Example:

SQL
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';

See also#