Get the App
SLTechnology News&Howtos  ›  Database  › 

How to solve the character set mismatch problem of mysql query

Shulou Source: shulou.com Published: 2022-06-01 02:39:21 10月03日 Update

This article mainly introduces how to solve the mysql query character set mismatch problem, the article is very detailed, has a certain reference value, interested friends must read it!

Sometimes the MySQL database uses the latin character set when building the table, while the query in the web page is utf-8. When the input page is typed in Chinese, and then queried in the database, it will report the error of ER_CANT_AGGREGATE_2COLLATIONS: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation'=', so the database is found in stackover flow. And the method of changing the character set in the data table.

SET collation_connection = 'utf8_general_ci'

Note: to replace the following two sentences with your database name and your 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, so that there will be no errors in querying the contents of the database when typing in Chinese.

Reference:Illegal mix of collations MySQL Error

Set the character set of the database to utf-8 in PHP

Mysqli_set_charset ($dbc,'utf8')

Just add a meta that displays utf-8 to html.

The above is how to solve the mysql query character set mismatch all the content, thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Data database character set query content time utf-8 input question name data table error Chinese value interest buddy partner method more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Xiaomi Shulou Technology vpn Redmi