mysqldude
Error codes › 1267

MySQL & MariaDB error 1267: Illegal mix of collations

Error messageIllegal mix of collations (…,…) and (…,…) for operation '…'
Example from our test runs: Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_unicode_ci,IMPLICIT) for operation '=' (5.6.51)

Two strings with different collations (or character sets) are compared, and the server can't decide which rules to use. Common after upgrades, because MySQL 8.0's default collation changed to utf8mb4_0900_ai_ci.

MySQLMariaDB
SymbolER_CANT_AGGREGATE_2COLLATIONSER_CANT_AGGREGATE_2COLLATIONS
SQLSTATEHY000HY000
TypeServer errorServer error
Versionsevery release since 5.0 activeevery release since 5.5 active

What it means

Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_unicode_ci,IMPLICIT) for operation '='. A collation defines how strings compare (case, accents, sort order). When both sides of a comparison, JOIN or UNION have equal priority but different collations, the server refuses to pick one.

Why it happens

  • Tables created at different times: older ones with utf8mb4_general_ci or utf8mb4_unicode_ci, newer ones with MySQL 8.0’s default utf8mb4_0900_ai_ci (or MariaDB 11.4+‘s utf8mb4_uca1400_ai_ci).
  • A stored procedure or function whose parameters took the database default collation when it was created, compared with a column that has another.
  • The connection collation (collation_connection) differs from the column’s when comparing to string literals or user variables.
  • Mixing character sets, such as a latin1 column and a utf8mb4 column.

How to fix it

  • Quick fix in the query: … ON a.s = b.s COLLATE utf8mb4_general_ci. This prevents index use on the converted side.
  • Proper fix: give the columns the same collation: ALTER TABLE b CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; (or the reverse). Check the whole schema with SELECT table_name, column_name, collation_name FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND collation_name IS NOT NULL;
  • Set a consistent default for new objects: ALTER DATABASE … COLLATE … and in the server config.

Reproduce it yourself

These steps are the exact test our harness runs. Use a scratch server, never production.

  1. Connect with mysql -u root -p and create a scratch database and the test data:

    CREATE DATABASE demo;
    USE demo;
    CREATE TABLE a (s VARCHAR(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci);
    CREATE TABLE b (s VARCHAR(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci);
    INSERT INTO a VALUES ('x');
    INSERT INTO b VALUES ('x');
  2. Run:

    SELECT * FROM a JOIN b ON a.s = b.s;

You get: Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_unicode_ci,IMPLICIT) for operation '='(11.8.9)

Verified fixes

  1. Force one collation in the comparison (quick fix)

    SELECT a.s FROM a JOIN b ON a.s = b.s COLLATE utf8mb4_general_ci;
  2. Make the columns use the same collation (proper fix)

    ALTER TABLE b MODIFY s VARCHAR(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
    SELECT a.s FROM a JOIN b ON a.s = b.s;

Tested on

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.8
Compare two columns with different collations
repro
✓ 1267✓ 1267✓ 1267✓ 1267✓ 1267✓ 1267✓ 1267✓ 1267✓ 1267
Force one collation in the comparison (quick fix)
fix
✓✓✓✓✓✓✓✓✓
Make the columns use the same collation (proper fix)
fix
✓✓✓✓✓✓✓✓✓
Compare two columns with different collations repro
MySQL 5.6✓ 12675.7✓ 12678.0✓ 12678.4✓ 12679✓ 1267
MariaDB 10.6✓ 126710.11✓ 126711.4✓ 126711.8✓ 1267
Force one collation in the comparison (quick fix) fix
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
Make the columns use the same collation (proper fix) fix
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
✓works ✓ 1062fails with the error the step demonstrates ⚠works with a warning ≠runs, result differs ✗fails Tested 2026-11-25 on 5.6.51, 5.7.44, 8.0.46, 8.4.13, 9.7.4, 10.6.28, 10.11.19, 11.4.13, 11.8.9

Related errors

  • 1270 ER_CANT_AGGREGATE_3COLLATIONS
  • 1271 ER_CANT_AGGREGATE_NCOLLATIONS
  • 1366 ER_TRUNCATED_WRONG_VALUE_FOR_FIELDexplained