Mysql statement: set names UTF8

Source: Internet
Author: User


Mysql statement: set names UTF8 has always known only mysql_query ("set names UTF8"); it sets the database encoding, but it has never been clear what "set names UTF8" is. It is not until today that the set names... is a mysql statement. I really feel that my homework has not been completed yet, and my current knowledge reserves are scarce. Write down the relevant information: www.2cto.com 1. set names 'charset _ name' set names displays the character sets used in the SQL statements sent by the client. Therefore, the set names 'cp1251 'statement tells the server to use the character SET cp1251 for future information sent from this client ". It also specifies the character set for the results sent from the server back to the client. (For example, if you use a SELECT statement, it indicates the character set used by the column value .) 2. Connecting character sets and checking (1) Some character sets and checking rule system variables are related to the interaction between the client and the server. · Server character sets and verification rules can be used as the value of character_set_server and collation_server variables. · Default database character sets and verification rules can be used as character_set_database and collation_database variable values. Character Set and checking rule variables are also involved in client-to-server connection. Each client has a connection-related character set and checking rule variable. Www.2cto.com (2) considers what is a "connection": what it does when connecting to the server. The client sends SQL statements, such as queries, to the server through connections. The server sends a response to the client through a connection, such as a result set. For client connection, this will cause some problems about the character set and proofreading rules of the connection. These problems can be solved through system variables: (3) when the query leaves the client, which character set is used in the query? The server uses the character_set_client variable as the character set used in the query sent by the client. (4) What character set should the server convert to after receiving the query? During conversion, 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 text has a prefix like _ latin1 or _ utf8 ). Collation_connection is important for comparing text strings. It is not important to compare the column value strings because the column has a higher priority for checking rules. (5) which character set should the server convert to before sending the result set or returning the error message to the client? The character_set_results variable indicates that the server returns 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 ). Example of www.2cto.com: mysql_query ("set names 'utf8'"); // use utf8 encoding;

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.