Skip to main content

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:
Find all columns of a specific type across all tables:

Indexes

List all indexes on a table:
Find tables with no primary key:

Constraints

List all constraints (PRIMARY KEY, UNIQUE, FOREIGN KEY, CHECK):
List all foreign keys and what they reference:
List CHECK constraints:

Stored Routines

List all stored procedures and functions:
View a routine’s definition:

Views and Triggers

List all views:
List all triggers:

Privileges

View effective privileges for the current user:

Key Tables Reference

INFORMATION_SCHEMA vs SHOW Commands

SHOW commands are shorthand that often have an INFORMATION_SCHEMA equivalent: 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 against TABLES 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

See also