Solution to the Problem of Character Set mismatch in mysql query, mysql Character Set
Problems Found
Recently, I encountered a problem in my work. When creating a table in MySQL database, I used the latin character set while the query on the webpage was UTF-8. When I enter Chinese characters on the input page, then, when querying in the database, it will reportER_CANT_AGGREGATE_2COLLATIONS: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='
This error occurs, so we found the method for changing the character set in the database and data table in stackover flow.
SET collation_connection = 'utf8_general_ci'
Note:Replace the following two statements with your database name and data table name.
ALTER DATABASE your_database_name CHARACTER SET utf8 COLLATE utf8_general_ci ALTER TABLE your_table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci
This ensures that the database is also a UTF-8 character set and will not generate an error when querying the database content during Chinese input.
Reference: Illegal mix of collations MySQL Error
Set the database character set to UTF-8 in PHP
mysqli_set_charset($dbc,'utf8');
Add the meta that displays UTF-8 in html.
<meta charset="utf-8">
Summary
Well, the above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, you can leave a message, thank you for your support.