(6) The character set in MySQL

Source: Internet
Author: User

Overview

?? Essentially, a computer recognizes only binary code, so that, regardless of the computer program or the data it processes, it must eventually be converted to binary code to be recognized by the computer. Each text symbol is encoded for computer recognition processing, which is the origin of the computer character set.

Select the appropriate character set

MySQL5.6 supports dozens of character sets, including UCS-2, UTF-16, Utf-16le, UTF-32, UTF-8, UTF8MB4 and other Unicode character sets, and the choice of character sets can take several factors into account:

    1. To meet the application support language requirements, if the application needs to handle a variety of text, should choose Unicode encoding, for MySQL, recommended for UTF-8;
    2. If the application involves the import of existing data, take into account the compatibility of the database character set with the existing data.
    3. If the database only needs to support the general Chinese, the data is large, the performance requirements are high, it can choose the double-byte fixed length encoding Chinese character set, such as GBK, because compared to the UTF-8,GBK is small, each Chinese character only 2 bytes, utf-8 Chinese characters need 3 bytes; Conversely, if the English characters are mainly processed, Choosing UTF-8 is better because the West character encoding in Gbk,ucs-2,utf-16 is 2 bytes.
    4. If the database needs to do a lot of character operations, it is better to choose a fixed-length character set.
    5. If all client programs support the same character set, the character set is preferred as the character set of the database.

Common Character Set comparisons:

MySQL Character set
    1. MySQL supports different character sets for different fields in the same server, the same database, or even the same table.
    2. The MySQL character set includes 字符集 and, 校对规则 where character sets are used to define how MySQL stores strings, proofing rules are used to define how strings are compared, and character sets are a one-to-many relationship with proofing rules.
    3. MySQL has 4 levels of default settings: Server-level, database-level, table-level, field-level. The server level can be set in the MySQL configuration file (my.cnf), and the character-set-server=utf-8 other is set at the time of creation.
    4. For real-world applications, there is also a set of character sets and proofing rules between the client and server. MySQL provides 3 parameter settings:, character_set_client character_set_connection character_set_results The character set that represents the client, the connection, and the result is returned. These 3 parameters are not normally set individually, and can be set by command: set names *** or set in My.cnf default-character-set=utf-8 .

The MySQL character set system variable has the following meanings:

(6) The character set in MySQL

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.