How to Fix the Illegal Mix of Collations Error in MySQL
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
This guide covers how to fix the “illegal mix of collations” error in MySQL.
The “illegal mix of collations” error in MySQL, identified by error code 1267, occurs when you try to compare or combine text columns with incompatible collations (collations are a set of rules for comparing characters in a character set). This error is common when performing operations like JOIN, WHERE, or ORDER BY on columns with different collations.
You can identify this error when MySQL returns the message: “Illegal mix of collations (collation1) and (collation2) for operation ‘operation_name’”. The error code associated with this issue is 1267.
To diagnose the problem, check the collation of the involved columns, tables, or databases. Use the following SQL commands:
SELECT COLLATION_NAME FROM information_schema.columns WHERE table_schema = 'your_database' AND table_name = 'your_table';
SHOW TABLE STATUS LIKE 'your_table';
SHOW CREATE DATABASE your_database;
Once you’ve identified the collation differences, align them. You can do this at the column, table, or database level. Here’s how to update the collation:
ALTER TABLE your_table MODIFY your_column VARCHAR(255) COLLATE desired_collation;
ALTER TABLE your_table CONVERT TO CHARACTER SET charset_name COLLATE desired_collation;
ALTER DATABASE your_database CHARACTER SET charset_name COLLATE desired_collation;
To prevent future errors, set a default collation at the server or database level:
[mysqld]
character-set-server = charset_name
collation-server = collation_name
CREATE DATABASE your_database CHARACTER SET charset_name COLLATE collation_name;
If for some reasons you can’t modify database collations, you can handle collation differences in your application code. Just convert strings to a consistent collation before sending them to the database.
During troubleshooting, Basedash helps teams move faster by combining AI-assisted analysis with direct SQL access, so you can validate fixes, monitor results, and share clear dashboards after incidents are resolved.
Written by
Senior Engineer at Basedash
Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.
Basedash lets you build charts, dashboards, and reports in seconds using all your data.