How to Fix MySQL Error 1253: Collation Is Not Valid for Character Set

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

  1. Using a utf8 collation on a utf8mb4 column. For example, specifying COLLATE utf8_general_ci on a column defined as CHARACTER SET utf8mb4. The utf8_* collation family only applies to the 3-byte utf8 charset; utf8mb4 requires its own collation family (utf8mb4_*).

  2. Using a utf8mb4 collation on a latin1 or latin2 column. Specifying COLLATE utf8mb4_unicode_ci on a column whose character set is latin1 is invalid for the same reason in the opposite direction.

  3. Inline COLLATE on 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.

  4. ORM or migration tool generating mismatched DDL. Some frameworks hardcode a collation without checking the actual character set of the target column or database.

  5. Copy-paste errors in schema scripts. Copying a COLLATE latin1_swedish_ci clause into a schema that uses utf8mb4 is a common mistake in long-running migration scripts.

Troubleshooting and Resolution Steps

  1. 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';
    
  2. 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';
    
  3. 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;
    
  4. 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
    );
    
  5. 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;
    
  6. 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;
    
  7. 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 COLLATE clause in your query with whatever character_set_connection reports.

Additional Information

  • The utf8 charset in MySQL is a 3-byte subset of Unicode. MySQL 8.0 changed the default charset to utf8mb4, so schemas created on 5.7 and altered on 8.0 can end up with mixed utf8/utf8mb4 collations — 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_ci became the default collation for utf8mb4. Code that previously relied on utf8mb4_general_ci or utf8mb4_unicode_ci should 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.charSet and hibernate.connection.collation in your dialect properties. With SQLAlchemy, pass charset=utf8mb4 in 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.

Subscribe to the Pulse Newsletter

Get early access to new Pulse features, insightful blogs & exclusive events , webinars, and workshops.

We use cookies to provide an optimized user experience and understand our traffic. To learn more, read our use of cookies; otherwise, please choose 'Accept Cookies' to continue using our website.