Get the App
SLTechnology News&Howtos  ›  Database  › 

Related Operation of GBK character set and UTF8 character Encoding in MySQL

Shulou Source: shulou.com Published: 2022-06-01 18:15:20 10月03日 Update

The following is about the operations related to the GBK character set and UTF8 character encoding in MySQL. The secret of the text is that it is close to the topic. So, no gossip, let's go straight to the following, I believe you will benefit from reading this article on the operation of GBK character set and UTF8 character coding in MySQL.

How GBK and UTF8 are actually stored in the system:

1 、 GBK:

> SELECT hex (convert ('Hello' using gbk))

+-+

| | hex (convert ('Hello' using gbk)) |

|-- |

| | C4E3BAC3 |

+-+

The GBK character set is divided according to four lengths, so the corresponding relationship is obtained:

You-- > C4E3

Okay-- > BAC3

2 、 UTF-8:

> SELECT hex (convert ('Hello' using utf8))

+-+

| | hex (convert ('Hello' using utf8)) |

|-- |

| | E4BDA0E5A5BD |

+-+

The UTF8 character set is divided into six lengths, so the corresponding relationship is obtained:

You-- > E4BDA0

Okay-- > E5A5BD

So we can find something different. If we use the "hello" stored in UTF-8 (the corresponding underlying storage is: E4BDA0E5A5BD), but use GBK to read, GBK will split the E4BDA0E5A5BD according to every 4 bit length, and finally split it into E4BDA0E5A5BD.

(below)

> SELECT CONVERT (unhex ('E4BDA0E5A5BD') USING GBK)

+-- +

| | CONVERT (unhex ('E4BDA0E5A5BD') USING GBK) | |

+-- +

| | raccoon garbage |-- > it will become garbled if it is read by GBK. |

+-- +

> SELECT hex (convert ('racon' using gbk))

+-+

| | hex (convert ('racon' using gbk)) | |

+-+

| | E4BD |

+-+

> SELECT hex (convert ('clients' using gbk))

+-+

| | hex (convert ('using gbk')) | |

+-+

| | A0E5 |

+-+

> SELECT hex (convert ('clients' using gbk))

+-+

| | hex (convert ('using gbk')) | |

+-+

| | A5BD |

+-+

In addition, the hexadecimal code is inversely deduced to UTF8-encoded Chinese characters:

> SELECT CONVERT (unhex ('E4BDA0E5A5BD') USING utf8)

+-- +

| | CONVERT (unhex ('E4BDA0E5A5BD') USING utf8) | |

+-- +

| | Hello |

+-- +

> SELECT CONVERT (unhex ('E4BDA0E5A5BD') USING GBK)

+-- +

| | CONVERT (unhex ('E4BDA0E5A5BD') USING GBK) | |

+-- +

| | raccoon garbage |-- > it will become garbled if it is read by GBK. |

+-- +

Is there anything you don't understand about the operations related to the GBK character set and UTF8 character encoding in the above MySQL? Or if you want to know more about it, you can continue to follow our industry information section.

Tags: Character Hello character set Encoding method length garbled place UTF-8 different following theme content Secret actual underlying text more Block look Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia vpn Xiaomi Shulou Technology Shulou Tech Info