MySQL
collation
database
table structure
SQL tips

How to check the collation of a table in MySQL

Codemia Knowledge Hub ·

Run SHOW TABLE STATUS LIKE 'table_name' and read the Collation field, or query information_schema.tables for table_collation. Collation also exists at the database and column level, so a table check is not always the whole story when you are debugging case sensitivity, odd ORDER BY results, or comparison mismatches.

Check table collation with SHOW TABLE STATUS

sql
SHOW TABLE STATUS LIKE 'users';

The Collation field is the table's default collation. This is convenient in an interactive client because it also shows engine, row count, and other metadata.

Query information_schema.tables

For scripts, admin tooling, or checking many tables at once, query the metadata directly:

sql
1SELECT table_schema,
2       table_name,
3       table_collation
4FROM information_schema.tables
5WHERE table_schema = 'app_db'
6  AND table_name = 'users';

Check column collations too

Individual text columns can override the table collation:

sql
1SELECT column_name,
2       character_set_name,
3       collation_name
4FROM information_schema.columns
5WHERE table_schema = 'app_db'
6  AND table_name = 'users';

If one column uses utf8mb4_bin while the table default is utf8mb4_unicode_ci, comparisons on that column can behave differently than you expect.

What collation changes in query results

Collation controls:

  • case sensitivity
  • accent sensitivity
  • sort order
  • string equality and grouping

A case-insensitive collation such as utf8mb4_general_ci treats Alice and alice as equal for many comparisons; a binary collation does not. That can subtly change results for WHERE, ORDER BY, GROUP BY, and unique indexes.

Check the database default

If new tables get surprising collations, look at the database defaults:

sql
1SELECT schema_name,
2       default_character_set_name,
3       default_collation_name
4FROM information_schema.schemata
5WHERE schema_name = 'app_db';

A table usually inherits its character set and collation from the database at creation time unless you set them explicitly. Changing the database default later does not change existing tables.

Change a table's collation

sql
ALTER TABLE users
CONVERT TO CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;

This is more than a metadata change. It can rebuild text columns and affect indexes, sorting, and comparisons, so run it carefully on production tables, especially large ones.

Debugging order for collation problems

  1. Database default collation
  2. Table default collation
  3. Individual column collations
  4. Session or query-level overrides

Working through the layers finds where behavior diverges instead of assuming the problem is at the table level.

Mistakes to avoid

  • Checking only the table and forgetting that columns can override it.
  • Assuming the database default still matches tables created long ago.
  • Confusing character set with collation: they are related but not the same.
  • Changing collation on a live table without considering indexes and application behavior.
  • Debugging case sensitivity in the application when the cause is a database collation choice.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design