ERROR 1253 (42000): COLLATION 'collation_name' is not valid for CHARACTER SET 'charset_name' is raised when a COLLATE clause references a collation that does not belong to the character set of the column, expression, or database object being defined or queried. The error symbol is ER_COLLATION_CHARSET_MISMATCH.
Impact
This error is a hard failure — MySQL rejects the statement immediately and no rows are inserted, updated, or returned. It appears at DDL time (when creating or altering tables, databases, or columns) as well as at query time (when a COLLATE operator is used inline in a SELECT, ORDER BY, WHERE, or CONVERT ... USING expression).
Developers most often encounter it after migrating a schema between servers with different default character sets, copy-pasting collation names from documentation without checking the target character set, or upgrading MySQL versions where collation defaults shifted (notably the utf8 to utf8mb4 change in MySQL 8.0). ORMs like Hibernate, SQLAlchemy, or ActiveRecord can surface it as a generic database exception when they apply collation hints during schema generation.
Common Causes
Using a
utf8collation on autf8mb4column. For example, specifyingCOLLATE utf8_general_cion a column defined asCHARACTER SET utf8mb4. Theutf8_*collation family only applies to the 3-byteutf8charset;utf8mb4requires its own collation family (utf8mb4_*).Using a
utf8mb4collation on alatin1orlatin2column. SpecifyingCOLLATE utf8mb4_unicode_cion a column whose character set islatin1is invalid for the same reason in the opposite direction.Inline
COLLATEon a string literal or expression where the collation family does not match the connection charset. The connection character set determines the collation family that is valid for unadorned string literals.ORM or migration tool generating mismatched DDL. Some frameworks hardcode a collation without checking the actual character set of the target column or database.
Copy-paste errors in schema scripts. Copying a
COLLATE latin1_swedish_ciclause into a schema that usesutf8mb4is a common mistake in long-running migration scripts.
Troubleshooting and Resolution Steps
Identify the mismatch — check what collation the object actually uses.
-- For a table or column SHOW CREATE TABLE your_table\G -- For all columns in a table SELECT column_name, character_set_name, collation_name FROM information_schema.columns WHERE table_schema = 'your_db' AND table_name = 'your_table';Find which collations are valid for a given character set.
-- List all collations for utf8mb4 SHOW COLLATION WHERE Charset = 'utf8mb4'; -- List all collations for latin1 SHOW COLLATION WHERE Charset = 'latin1';Fix a column definition that uses the wrong collation. Replace the collation with one that matches the column's character set.
-- Wrong: utf8 collation on a utf8mb4 column ALTER TABLE users MODIFY COLUMN name VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8_general_ci; -- ERROR 1253 -- Correct: matching collation ALTER TABLE users MODIFY COLUMN name VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;Fix a CREATE TABLE statement.
-- Wrong CREATE TABLE products ( title VARCHAR(200) CHARACTER SET utf8mb4 COLLATE utf8_general_ci ); -- Correct CREATE TABLE products ( title VARCHAR(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci );Fix an inline COLLATE in a query. Ensure the collation belongs to the same charset as the column or expression.
-- Wrong: column is utf8mb4, collation is utf8 SELECT * FROM products ORDER BY title COLLATE utf8_general_ci; -- Correct SELECT * FROM products ORDER BY title COLLATE utf8mb4_general_ci;Fix a database-level collation mismatch.
-- Check database charset and collation SELECT schema_name, default_character_set_name, default_collation_name FROM information_schema.schemata WHERE schema_name = 'your_db'; -- Alter the database if needed ALTER DATABASE your_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;Check the connection character set if the error occurs on a string literal.
SHOW VARIABLES LIKE 'character_set_connection'; SHOW VARIABLES LIKE 'collation_connection';Align the
COLLATEclause in your query with whatevercharacter_set_connectionreports.
Additional Information
- The
utf8charset in MySQL is a 3-byte subset of Unicode. MySQL 8.0 changed the default charset toutf8mb4, so schemas created on 5.7 and altered on 8.0 can end up with mixedutf8/utf8mb4collations — a common source of this error. - Related error codes: 1267 (
ER_CANT_AGGREGATE_2COLLATIONS) is raised when MySQL cannot determine a single collation from two operands in a comparison or concatenation — often a downstream symptom of mismatched charset/collation configurations. - In MySQL 8.0,
utf8mb4_0900_ai_cibecame the default collation forutf8mb4. Code that previously relied onutf8mb4_general_ciorutf8mb4_unicode_cishould still work, but mixing them in a single expression triggers error 1267, not 1253. - ORM frameworks: when using Hibernate with MySQL 8, set both
hibernate.connection.charSetandhibernate.connection.collationin your dialect properties. With SQLAlchemy, passcharset=utf8mb4in the connection URL and let the ORM derive the collation rather than specifying it explicitly.
Frequently Asked Questions
Why does my schema work on MySQL 5.7 but fail on 8.0?
MySQL 8.0 changed the default character set from utf8 (3-byte) to utf8mb4 (4-byte). If your schema was created on 5.7 with utf8_general_ci collations and you run DDL against it on an 8.0 server that expects utf8mb4, you may end up with mismatched charset/collation pairs, triggering error 1253.
Can I just change the collation without changing the character set?
Yes, but only to a collation that belongs to the current character set. If you want to switch to a utf8mb4_* collation you must also change the column's character set to utf8mb4. Use ALTER TABLE ... CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci to update all columns in a table at once.
How do I find all columns in my database that have a charset/collation mismatch?
SELECT table_name, column_name, character_set_name, collation_name
FROM information_schema.columns
WHERE table_schema = 'your_db'
AND collation_name NOT LIKE CONCAT(character_set_name, '%')
ORDER BY table_name, column_name;
Any row returned here has a collation that does not begin with its column's character set name — a clear mismatch.
Does this error occur at runtime or only at schema definition time?
Both. Error 1253 is raised whenever a COLLATE clause appears in a statement — whether in CREATE TABLE, ALTER TABLE, or inline in a SELECT/ORDER BY/WHERE clause. It is a parse/validation error, so the entire statement is rejected before any rows are read or written.