The specific role of variable character_set_connection in MySQL

Source: Internet
Author: User

title. In general use, the values of the two variables are the same character_set_client,character_set_connection, that is, the query does not require an encoding conversion. It seems that the variable character_set_connection is somewhat superfluous. When the query enters, the query is converted from character_set_client to character_set_connection by the server, and when the query executes, the query is converted from character_set_connection to the column character set by the server. When the query is reversed, the data is converted directly from the column character set by the server to Character_set_results. It is obvious that the query entry has undergone a conversion more than the query return, is this necessary, what is the point?

refer to MySQL Chinese manual:

10.3.6. Connecting character sets and proofing
some character set and collation system variables are related to client and server interactions. In the previous chapters, we have already mentioned some of the following:
· Server character sets and proofing rules can be used as values for Character_set_server and collation_server variables.

· The character set and proofing rules for the default database can be used as values for character_set_database and collation_database variables.

Character set and proofing rule variables are also involved in connection processing for clients and servers. Each client has a connection-related character set and proofing rule variables.

consider what a "connection" is: It is what you do when you connect to the server. The client sends an SQL statement, such as a query, to the server via a connection. The server sends a response over a connection to the client, such as a result set. For client connections, this can cause problems with connection character sets and proofing rules that can be resolved by system variables:

· When the query leaves the client, what character set is used in the query?

the server uses the Character_set_client variable as the character set used in queries sent by the client.

· What kind of character set should the server convert to after it receives a query?

when converting, the server uses character_set_connection and collation_connection system variables. It converts the query sent by the client from the character_set_client system variable to character_set_connection (unless the string literal has a preposition like _latin1 or _utf8). Collation_connection is important for comparing literal strings. For string comparisons of column values, it is not important because the column has a higher collation precedence.

· What character set should the server convert to before sending a result set or returning an error message to the client?



The character_set_results variable instructs the server to return the query result to the character set used by the client. Includes result data, such as column values and result metadata, such as column names.

This is the MySQL character set mechanism, or there is a certain role

Doing so allows different clients to have different character sets. The typical example is, I have a utf-8 site, this site is a charset client for Utf-8 clients. At the same time, I might need to read and write the database on a GBK terminal, which is a client, but its character set is GBK.

Different connections, they all have their own character_set_client,character_set_connection, unrelated. The kind of demand you said above, I feel that even if there is no character_set_connection, only need character_set_client as can be achieved.

The specific role of variable character_set_connection in MySQL

Related Article

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.