How to Fix MySQL Error 1270 (ER_CANT_AGGREGATE_3COLLATIONS)
You get mysql error 1270 when a single operation combines three incompatible text collations. You fix it by aligning column, session, and literal collations to one standard. MySQL logs this failure under symbol ER_CANT_AGGREGATE_3COLLATIONS and SQLSTATE HY000. The engine stops the query because it cannot pick one sorting rule for three inputs. This issue often appears during string replacement, case checks, or three-table joins. What causes mysql error 1270 in your database Every text value
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You get mysql error 1270 when a single operation combines three incompatible text collations. You fix it by aligning column, session, and literal collations to one standard.
MySQL logs this failure under symbol ER_CANT_AGGREGATE_3COLLATIONS and SQLSTATE HY000. The engine stops the query because it cannot pick one sorting rule for three inputs. This issue often appears during string replacement, case checks, or three-table joins.
What causes mysql error 1270 in your database
Every text value in MySQL carries a character set and a collation rule. The collation tells the engine how to compare and sort text strings. MySQL also assigns a priority rank to each text input in a query. Column values, client variables, and literal strings each hold different priority ranks.
When a function takes three text inputs, MySQL compares all three collations at once. If all three use different rules with matching priority, the engine cannot choose one. It stops execution and returns the illegal mix of collations message for that operation.
This problem often starts after a partial database upgrade or table import. Older tables might keep legacy character sets while new tables use modern defaults. At the same time, your app driver might open sessions with a third collation. When one query touches both tables and a session variable, the conflict triggers.
How to find the mismatched collations
Start by reading the full error message in your database log. The message lists the three conflicting collations and their priority types in order. It also names the exact function or operator that failed during the run.
Next, check the schema metadata for every table and column in that query. Look at the table status and column rules to see their stored collations. Do not guess the column settings from the database default alone. A single column can hold its own rule that overrides the table setting.
MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Then, check the session variables for the app user running the failed query. Inspect the client, connection, and result collation settings for that active session. Often, an app driver or ORM sends its own collation during login. Comparing column rules against session settings will reveal where the third collation enters.
How to fix the collation conflict in production
You can fix the query fast by adding an explicit collation cast in SQL. This tells the engine which sorting rule to use for the three inputs. It works well as a quick patch when you cannot alter tables right away. Keep in mind that casting a column in a filter can skip index usage.
For a permanent fix, align your session settings and table schemas to one collation. Update your app driver setup so new sessions match your main database character set. If an old table uses a legacy rule, plan a safe schema change.
Test any table rebuild in a staging setup before touching production data. Converting column text rules can lock tables and change how unique keys behave. Run the change during low traffic hours with a limited role and full backups.
Inspect every MySQL query and response in flight
Static grants and network rules block bad logins. They cannot pause a risky query for review or mask emails in a result set. By design, hoop.dev sits inline in the MySQL protocol as a sidecar for your MySQL. For every plain query, prepared statement, or cursor an agent or human runs in production, hoop.dev decides to pass, mask, block, or hold it for review.
First, hoop.dev guardrails block banned actions before MySQL runs them, and an AI Analyzer you configure can score intent or escalate for approval. Next, hoop.dev data masking rewrites sensitive string columns in results in memory, and every verdict goes to the audit trail. Find the open-source binary on GitHub.
Frequently asked questions
How does error 1270 differ from error 1267 in MySQL?
Error 1267 happens when an operation mixes two incompatible collations, such as a simple comparison. Error 1270 happens when an operation takes three inputs and cannot merge their three collations.
Which SQL operations trigger ER_CANT_AGGREGATE_3COLLATIONS most often?
Functions that take three string arguments trigger this error most often in production. Common examples include string replace functions, range checks between strings, and multi-branch case statements.
Can I fix this error without altering production tables?
Yes, you can align the client session collation or add explicit collation casts in queries. This resolves the three-way conflict at runtime without changing stored table schemas.
Related guides
In this post