MySQL Collation Mismatch Error: 'Illegal mix of collations...' - How to Fix
This error message indicates a mismatch in collation settings between the columns you're comparing in your query. Collation defines how string comparison and sorting occur within a database, with each column potentially having a unique collation.
In your case, you're trying to compare columns with different collations: 'utf8mb4_general_ci' and 'utf8mb4_0900_ai_ci'. The '=' operator, used for equality comparison, requires both operands to share the same collation.
Here's how to resolve this issue:
-
Change a Column's Collation:
Modify the collation of one column to match the other using theALTER TABLEstatement.ALTER TABLE your_table MODIFY COLUMN column_name VARCHAR(255) COLLATE utf8mb4_general_ci;Replace 'your_table' and 'column_name' with your actual table and column names.
-
Convert in Your Query:
Explicitly specify a common collation for one column using theCOLLATEkeyword during the comparison.SELECT * FROM your_table WHERE column1 COLLATE utf8mb4_general_ci = column2;Replace 'your_table', 'column1', and 'column2' with your table and column names.
-
Specify Collation in Joins:
If the columns are part of a join condition, define the collation within theONclause of the join.SELECT * FROM table1 INNER JOIN table2 ON table1.column1 COLLATE utf8mb4_general_ci = table2.column2;Replace 'table1', 'column1', 'table2', and 'column2' with your table and column names.
Choose the option that best suits your needs and adjust the collations accordingly.
AI 优化版
原文地址:https://www.cveoy.top/t/topic/p1Fr 著作权归作者所有。请勿转载和采集!