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

Reasons and methods for Waiting for table metadata lock in MySQL

When MySQL performs DDL operations such as alter ...

Optimize MySQL with 3 simple tweaks

I don't expect to be an expert DBA, but when ...

Comparison between Redis and Memcache and how to choose

I've been using redis recently and I find it ...

How to solve the 2002 error when installing MySQL database on Alibaba Cloud

The following error occurred while installing the...

How to detect file system integrity based on AIDE in Linux

1. AIDE AIDE (Advanced Intrusion Detection Enviro...

Solve the cross-domain problem of Vue+SpringBoot+Shiro

Table of contents 1. Configure Vue front end 1. D...

A brief talk about JavaScript Sandbox

Preface: Speaking of sandboxes, our minds may ref...

A detailed discussion on detail analysis in web design

In design work, I often hear designers participati...

Solutions to VMware workstation virtual machine compatibility issues

How to solve VMware workstation virtual machine c...

Detailed explanation of Linux text editor Vim

Vim is a powerful full-screen text editor and the...

How to install nginx in centos7

Install the required environment 1. gcc installat...

How to enable remote access in Docker

Docker daemon socket The Docker daemon can listen...

Let's talk briefly about the changes in setup in vue3.0 sfc

Table of contents Preface Standard sfc writing me...

How to install Linux flash

How to install flash in Linux 1. Visit the flash ...