VillageSQL is a drop-in replacement for MySQL with extensions.
All examples in this guide work on VillageSQL. Install Now →
INFORMATION_SCHEMA is a virtual database that exposes MySQL server metadata through standard SQL queries. Everything that SHOW TABLES, SHOW COLUMNS, and DESCRIBE can tell you, INFORMATION_SCHEMA can too — and with the full power of WHERE, JOIN, and aggregation.
Tables and Columns
List all tables in a database:table_rows is an estimate for InnoDB tables (derived from index statistics), not an exact count. Use SELECT COUNT(*) for precision.
List all columns for a table:
Indexes
List all indexes on a table:Constraints
List all constraints (PRIMARY KEY, UNIQUE, FOREIGN KEY, CHECK):Stored Routines
List all stored procedures and functions:Views and Triggers
List all views:Privileges
View effective privileges for the current user:Key Tables Reference
| Table | What it contains |
|---|---|
TABLES | All tables and views, with engine, row count estimates, sizes |
COLUMNS | All columns with types, defaults, nullability |
STATISTICS | Index definitions and cardinality |
TABLE_CONSTRAINTS | All constraints (PK, UK, FK, CHECK) |
KEY_COLUMN_USAGE | Columns in constraints, with FK target details |
REFERENTIAL_CONSTRAINTS | FK cascade/restrict rules |
CHECK_CONSTRAINTS | CHECK constraint expressions |
ROUTINES | Stored procedures and functions |
TRIGGERS | Trigger definitions |
VIEWS | View definitions |
CHARACTER_SETS | Available character sets |
COLLATIONS | Available collations |
SCHEMATA | All databases visible to the current user |
INFORMATION_SCHEMA vs SHOW Commands
SHOW commands are shorthand that often have an INFORMATION_SCHEMA equivalent:
| SHOW command | INFORMATION_SCHEMA equivalent |
|---|---|
SHOW TABLES | SELECT table_name FROM information_schema.tables WHERE table_schema = DATABASE() |
SHOW COLUMNS FROM t | SELECT * FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 't' |
SHOW INDEX FROM t | SELECT * FROM information_schema.statistics WHERE table_name = 't' |
SHOW CREATE TABLE t | No direct equivalent — SHOW CREATE TABLE is still the easiest way |
SHOW PROCEDURE STATUS | SELECT * FROM information_schema.routines WHERE routine_type = 'PROCEDURE' |
INFORMATION_SCHEMA queries are better when you need filtering, joining, or aggregation. SHOW commands are fine for interactive inspection.
Frequently Asked Questions
Are INFORMATION_SCHEMA queries slow?
For InnoDB tables, some queries (especially againstTABLES and STATISTICS) trigger index statistics updates, which can be slow on large schemas. If you’re querying metadata frequently, use mysql.innodb_table_stats and mysql.innodb_index_stats for faster access to cached statistics.
Why do table_rows values look wrong?
information_schema.tables.table_rows is an estimate from InnoDB’s index statistics, not a live count. It can be off by 40-50% for large tables. Run ANALYZE TABLE tablename to refresh the statistics, or use SELECT COUNT(*) for an exact count.
Troubleshooting
| Problem | Solution |
|---|---|
| Query returns no rows for a known table | The current user may lack SELECT privilege on the table — INFORMATION_SCHEMA filters results to tables the user can see |
table_rows is very different from COUNT(*) | InnoDB row counts are estimates — run ANALYZE TABLE to refresh index stats |
| Can’t find a constraint by name | Constraint names are scoped to the database — check constraint_schema in the WHERE clause |
Slow query against INFORMATION_SCHEMA.TABLES | InnoDB refreshes stats on access; use information_schema_stats_expiry (default 86400 seconds) to cache results longer |
See also
- MySQL User Management — INFORMATION_SCHEMA.USER_PRIVILEGES for auditing grants
- Schema Migrations in MySQL — querying INFORMATION_SCHEMA to inspect schema before migrating

