How to solve the problem of MySQL query character set mismatch

How to solve the problem of MySQL query character set mismatch

Find the problem

I recently encountered a problem at work. When creating a table in MySQL database, latin character set was used, while utf-8 was used for querying on the web page. When Chinese characters were entered on the input page and then queried in the database, ER_CANT_AGGREGATE_2COLLATIONS: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' .

SET collation_connection = 'utf8_general_ci'

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

This ensures that the database is also in the UTF-8 character set, so there will be no errors when querying the contents of the database when Chinese is input.

reference: Illegal mix of collations MySQL Error

Set the database character set to utf-8 in PHP

mysqli_set_charset($dbc,'utf8');

Just add meta to display utf-8 in HTML

<meta charset="utf-8">

Summarize

Well, the above is the full content of this article. I hope that the content of this article can bring some help to your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • MySQL character set viewing and modification tutorial
  • How to modify the MySQL character set
  • Causes and solutions to the garbled character set problem in MySQL database
  • How to change MySQL character set utf8 to utf8mb4
  • How to unify the character set on an existing mysql database
  • MySQL character set garbled characters and solutions
  • Detailed explanation of JDBC's processing of Mysql utf8mb4 character set
  • Solution to index failure in MySQL due to different field character sets
  • How to change the default character set of MySQL to utf8 on MAC
  • How to set the character set for mysql under Docker
  • Detailed explanation of character sets and validation rules in MySQL

<<:  React error boundary component processing

>>:  Use nginx.vim tool for syntax highlighting and formatting configuration nginx.conf file

Recommend

Detailed explanation of the use and precautions of crontab under Linux

Crontab is a command used to set up periodic exec...

How to expand the disk partition for centos system

Problem/failure/scenario/requirement The hard dis...

How to use JavaScript to determine several common browsers through userAgent

Preface Usually when making h5 pages, you need to...

Summary of frequently used commands for Linux file operations

0. New operation: mkdir abc #Create a new folder ...

Details of function nesting and closures in js

Table of contents 1. Scope 2. Function return val...

CSS overflow-wrap new property value anywhere usage

1. First, understand the overflow-wrap attribute ...

Process analysis of deploying ASP.NET Core applications on Linux system Docker

Table of contents 1. System environment 2. Operat...

Solution to inserting a form with a blank line above and below

I don't know if you have noticed when making a...

How to configure static network connection in Linux

Configuring network connectivity for Linux system...

How to operate MySQL database with ORM model framework

What is ORM? ORM stands for Object Relational Map...

MySQL query specifies that the field is not a number and comma sql

Core SQL statements MySQL query statement that do...

Detailed explanation of MySQL data grouping

Create Group Grouping is established in the GROUP...

Share 8 very useful CSS development tools

CSS3 Patterns Gallery This CSS3 pattern library s...

Discussion on the problem of garbled characters in iframe page parameters

I encountered a very unusual parameter garbled pro...