Solution to abnormal connection table caused by inconsistent MySQL character sets

Solution to abnormal connection table caused by inconsistent MySQL character sets

Doing a simple table query as follows, an error message is displayed directly. It turns out that the character set is inconsistent. This article records the character set type of MySQL and the solution to the following problem

select a.id, b.id from tt as a, t2 as b where a.xx = b.xx

-- Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8mb4_general_ci,IMPLICIT) for operation '='

1. Solution

Let's first look at the solution to the above problem. The easiest way to think of it is to unify the character sets of the two tables, either both are utf8mb4_general_ci or both are utf8mb4_unicode_ci. This problem will be naturally solved by unifying. What if I don't want to change the character set of the table? After all, in a production environment, doing this kind of operation is still risky. Here is a less elegant solution.

Specify the character set after the field (you can specify all of them as utf8mb4_general_ci or all of them as utf8mb4_unicode_ci, just process it according to your actual needs)

select a.id, b.id from tt as a, t2 as b where a.xx = b.xx collate utf8mb4_general_ci

2. MySQL character set

Character Set

For domestic partners, generally speaking, our common character sets are the following three

  • gbk: two bytes
  • utf8: three bytes
  • utf8mb4: four bytes

MySQL actually supports more, which can be queried through show charset;

Verification rules

In actual cases, we often see the following

  • utf8_bin
  • utf8mb4_unicode_ci
  • utf8mb4_general_ci
  • latin1_general_cs

Of course, we can also view the supported validation rules through show collation;

Please note the above wording

  • ci: case insensitive abbreviation is case insensitive
  • cs: case sensitive
  • bin: binary storage, case sensitive

This is the end of this article about how to solve the abnormality of connecting tables caused by inconsistent MySQL character sets. For more related content about abnormality of connecting tables caused by inconsistent MySQL character sets, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to modify and view the character set of MySql tables, fields, and libraries
  • MySQL character set and collation rules (MySQL collation set)
  • How to modify the database encoding (database character set) and the character encoding of the table in MySQL
  • In-depth analysis of Mysql character set settings
  • Detailed analysis of two methods to modify the MySQL default character set
  • Solving the Mysql5 character set encoding problem

<<:  A brief discussion on JavaScript scope

>>:  Two special values ​​in CSS are used to control the inherit and initial methods of the cascade

Recommend

Implementation of scheduled backup in Mysql5.7

1. Find mysqldump.exe in the MySQL installation p...

How to Install and Configure Postfix Mail Server on CentOS 8

Postfix is ​​a free and open source MTA (Mail Tra...

Two ways to implement HTML page click download file

1. Use the <a> tag to complete <a href=&...

Summary of the differences and usage of plugins and components in Vue

The operating environment of this tutorial: Windo...

How to implement concurrency control in JavaScript

Table of contents 1. Introduction to Concurrency ...

Use button trigger events to achieve background color flashing effect

To achieve the background color flashing effect, j...

JavaScript implementation of the Game of Life

Table of contents Concept Introduction Logical ru...

How to run the react project on WeChat official account

Table of contents 1. Use the a tag to preview or ...

Detailed explanation of the difference between in and exists in MySQL

1. Prepare in Advance For your convenience, I cre...

Basic ideas for finding errors in Web front-end development

WEB development mainly consists of two interactio...

A brief discussion on the VUE uni-app life cycle

Table of contents 1. Application Lifecycle 2. Pag...

Summary of common problems and solutions in Vue (recommended)

There are some issues that are not limited to Vue...