In-depth Mysql character set settings, in-depth mysql character set _ PHP Tutorial

Source: Internet
Author: User
Go deep into Mysql character set settings and mysql character set. Go deep into Mysql character set settings. there is a character set converter between mysql client and mysql server. Character_set_clientgbk: the converter knows how to go deep into Mysql character set settings and mysql character set

There is a character set converter between the mysql client and the mysql server. Character_set_client => gbk: the converter knows that the client sends the gbk encoding character_set_connection => gbk: converts the data sent from the client to the gbk character_set_results => gbk: Note:The preceding three character sets can be set using set names gbk. example: create table test (name varchar (64) not null) charset utf8; # utf8 indicates the character encoding on the server. first, insert a data inert into test values ('test') to the data table test. then, the data "test" is stored in the database in the "utf8" format:

First, the data is sent to the mysql server through the Mysql client. when the character_set_connection value is gbk, the data sent from the client is converted to gbk format, when the character set converter transmits the data to the server, it finds that the server saves the data by utf8. Therefore, the data is automatically converted from gbk to utf8 within the server. When will garbled characters appear?Use the header ('content-type: text/html; charset = utf8'); to convert the client data to utf8 format. when the data passes through the "character set converter, because character_set_client = gbk and character_set_connection is equal to gbk, the data transmitted from the client (in fact, in utf8 format) will not be converted. However, when the character set converter sends data to the server, it finds that the server requires utf8 format, so the current data will be processed as gbk format, and then converted to utf8 (however, this step is actually wrong ...). 2. when the result does not match the client page

Set the format of the returned result to utf8, but the format accepted by the client is gbk, so garbled characters will appear. Show character set syntax can be used to display all available character sets latin character sets

Note: The Maxlen column displays the maximum number of bytes used to store a single character. Utf8 character set

Gbk character set

When will data be lost?Compared with the above three images, we can know that in each character set, the maximum number of bytes used to store a character is different, utf8 is the maximum, and latin is the smallest. Therefore, when a character set converter is used, improper processing may cause data loss and cannot be recovered. For example: SetWhen the character_set_connection value is changed to lantin

The gbk data sent from the client is converted to the lantin1 format, because the gbk format occupies a large number of characters, resulting in data loss.

Summary:

There is a character set converter between the mysql client and the mysql server. Character_set_client = gbk: the converter knows the client...

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.