Illegal mix of collations utf8mb4_unicode_ci,IMPLICIT and utf8mb4_general_ci,IMPLICIT for operation ''
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
The MySQL error about an illegal mix of collations appears when the server must compare or combine strings that use different collation rules. A common example is utf8mb4_unicode_ci on one column and utf8mb4_general_ci on another. The fix is usually not in the query alone; it is in making your schema consistent so MySQL no longer has to guess how strings should be compared.
Why the Error Happens
A character set defines how text is stored. A collation defines how text in that character set is compared and sorted. Two columns may both use utf8mb4 and still be incompatible for some operations if their collations differ.
This can fail in joins, WHERE comparisons, UNION, ORDER BY, string functions, and concatenation. For example:
Even though both columns use utf8mb4, MySQL can reject the comparison because the collations are different.
Inspect the Actual Collations
Start by checking the column definitions, not just the database default. The mismatch often exists at the table or column level.
If multiple tables are involved, inspect every participating text column. The database default only affects newly created objects; it does not automatically rewrite older columns.
Short-Term Query Fix
If you need an immediate workaround for a single query, explicitly cast one side to the other collation:
You can do the same in a WHERE clause:
This solves the comparison for that statement, but it is not the best long-term fix. Repeating COLLATE across the codebase is noisy and easy to miss.
Long-Term Schema Fix
The durable fix is to standardize the collation across related columns, tables, or the entire schema. For many older applications that means choosing one of the existing utf8mb4 collations and converting everything to it.
To convert one table:
To convert one column:
If you are standardizing a whole schema, update the database default as well so new tables inherit the intended collation:
On MySQL 8, some teams prefer newer collations such as utf8mb4_0900_ai_ci. That can be a good choice, but consistency matters more than the specific collation name. Pick one standard and apply it everywhere relevant.
How to Choose Between unicode_ci and general_ci
utf8mb4_unicode_ci generally provides more linguistically correct comparisons than utf8mb4_general_ci. The general collation is older and simpler. In modern applications, the usual advice is to avoid mixing them rather than trying to keep both for performance reasons.
If your application already relies on one collation's exact comparison behavior, test carefully before converting production data. Sorting, uniqueness checks, and comparison outcomes can change.
Common Pitfalls
The biggest mistake is fixing only the query while leaving the schema inconsistent. The error then returns later in a join, migration, or report query.
Another common problem is updating the database default and assuming that old tables changed automatically. They did not. Existing tables and columns keep their previous definitions until you alter them explicitly.
It is also easy to overlook literals and connection settings. If the application connection uses a different character set or collation than the table, MySQL may still need coercion rules during comparison.
Finally, do not change collations blindly on large production tables. Rebuild cost, index behavior, and sort order changes should be evaluated before rollout.
Summary
- The error occurs when MySQL compares strings that use different collations.
- '
utf8mb4_unicode_ciandutf8mb4_general_cican conflict even though both useutf8mb4.' - '
SHOW FULL COLUMNSandSHOW CREATE TABLEhelp locate the real mismatch.' - '
COLLATEin a query is a short-term workaround.' - The long-term fix is to standardize table and column collations across the schema.
Related reading
- ImagePullBack pod status in Kubernetes when pulling public image MS SQL Server Express
- Implementation of Atomic Transactions in dynamodb
- Implementation of Levenshtein distance for mysql/fuzzy search?
- Implementing a distributed database system using Microsoft Excel (back-end) and JSP (front-end)
- Illegal pattern character 'T' when parsing a date string to java.util.Date
- Illegal reflective access by org.springframework.cglib.core.ReflectUtils1
- Implementing Comments and Likes in database
- Import data in MySQL from a CSV file using LOAD DATA INFILE

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.