Garbled analysis of Black Horse DAY09 database

Source: Internet
Author: User

Garbled Analysis:

First, in the cmd window, a CMD window is a client, and by default it is encoded using GBK, but the encoding is not changed.

When inputting Chinese characters "Zhang", the client uses GBK to encode: suppose: 1110

What decoding does the server use? We use show variables like "character%" and print the results as follows:

Explain:

-----+
| variable_name | Value
|
+--------------------------+------
-----+
| character_set_client | The UTF8 server considers the client to be encoded using UTF-8
|
| character_set_connection | UTF8 server considers client and server connections to be UTF-8 encoded
|
| Character_set_database | UTF8
|
| Character_set_filesystem | Binar
|
| Character_set_results | UTF8 server thinks the Print to command Line window uses UTF-8 encoding
|
| Character_set_server | Utf8
|
| Character_set_system | Utf8

Although the server thinks so, but the server thinks is wrong, so I need to let the server know that the client's encoding is GBK

Use set names GBK;

Then see show variables like "character%";


In this way the server will decode with GBK, then the server's encoding is character_set_database | UTF8

GBK----------------->utf-8 will be garbled?

In fact, the bottom is this, when the server uses GBK decoding, that is, string S=new string (1110,GBK), and then encode s.getbytes (utf-8) stored in the database.

When we take the data, it is the reverse process of the process, converted to GBK encoding sent, so the client will not see garbled.

Schematic diagram:




Garbled analysis of Black Horse DAY09 database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.