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:
- 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;
- If the application involves the import of existing data, take into account the compatibility of the database character set with the existing data.
- 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.
- If the database needs to do a lot of character operations, it is better to choose a fixed-length character set.
- 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
- MySQL supports different character sets for different fields in the same server, the same database, or even the same table.
- 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.
- 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.
- 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