The dreaded "Illegal mix of collations" error in MySQL often occurs when comparing data with mismatched character sets or collations. This guide shows you how to resolve this issue, specifically addressing the conflict between 'latin1_swedish_ci' and 'utf8_general_ci'.
For a quick fix affecting only your current MySQL connection, use this command:
<code class="language-sql">SET collation_connection = 'utf8_general_ci';</code>
This temporarily adjusts the collation for the session.
For a lasting solution, modify your database and table collations directly:
your_database_name
with your actual database name:<code class="language-sql">ALTER DATABASE your_database_name CHARACTER SET utf8 COLLATE utf8_general_ci;</code>
your_table_name
accordingly):<code class="language-sql">ALTER TABLE your_table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;</code>
By implementing these changes, you'll standardize your database and tables to use 'utf8_general_ci', eliminating future collation conflicts and ensuring consistent data handling.
The above is the detailed content of How to Fix the MySQL 'Illegal Mix of Collations' Error?. For more information, please follow other related articles on the PHP Chinese website!