Home > Database > Mysql Tutorial > body text

Solving the problem of query character set mismatch in MySQL

黄舟
Release: 2017-08-09 14:18:20
Original
1662 people have browsed it

This article mainly introduces to you the solution to the problem of mysql query character set mismatch. The article introduces it to you in great detail through sample code. It has certain reference and learning value for friends who also encounter this problem. Friends who need it, please follow the editor to learn together.

Found the problem

I recently encountered a problem at work. When the MySQL database created the table, it used the latin character set, and The query on the web page is utf-8. When you enter Chinese on the input page and then query in the database, it will report ER_CANT_AGGREGATE_2COLLATIONS: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation ' =' This error, so I found a way to change the character set in this database and data table in stackover flow.


SET collation_connection = 'utf8_general_ci'
Copy after login

Note: 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
Copy after login

This ensures that the database is also in the utf-8 character set, and there will be no errors in querying the content in the database when inputting in Chinese.

reference:Illegal mix of collations MySQL Error

Set the database character set to utf-8 in PHP


mysqli_set_charset($dbc,'utf8');
Copy after login

in html Just add the meta that displays utf-8 in


<meta charset="utf-8">
Copy after login

Summary

The above is the detailed content of Solving the problem of query character set mismatch in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template