In mysql5.5, you can query the character encoding through the "SHOW VARIABLES LIKE 'character%';" statement, which can display the character set used by the MySQL client, the character set used when connecting to the database, and create a database The character set used, the character set used by the database system, etc.
(Recommended tutorial: mysql video tutorial)
Characters (Character) are letters, numbers, and symbols in computers A general term for a character, a character can be a Chinese character, an English letter, an Arabic numeral, a punctuation mark, etc.
Computers store data in binary form. The numbers, English, punctuation marks, Chinese characters and other characters we usually see on the display are the result of binary number conversion.
Character set (Character set) defines the correspondence between characters and binary, and assigns unique numbers to characters. Common character sets include ASCII, GBK, IOS-8859-1, etc.
Character encoding (Character encoding) can also be called character set code, which specifies how to store character numbers in the computer.
Most character sets only correspond to one character encoding, such as: ASCII, IOS-8859-1, GB2312, GBK, which all represent both the character set and the corresponding character encoding. So in general, the two can be considered synonyms. The exception is the Unicode character set, which has three encoding schemes, UTF-8, UTF-16, and UTF-32. The most commonly used encoding is UTF-8.
In MySQL, you can view the character set currently used by MySQL through the SHOW VARIABLES LIKE 'character%';
command. The command and running results are as follows:
mysql> SHOW VARIABLES LIKE 'character%'; +--------------------------+---------------------------------------------------------+ | Variable_name | Value | +--------------------------+---------------------------------------------------------+ | character_set_client | gbk | | character_set_connection | gbk | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | gbk | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | C:\Program Files\MySQL\MySQL Server 5.7\share\charsets\ | +--------------------------+---------------------------------------------------------+ 8 rows in set, 1 warning (0.01 sec)
The description of the above running results is shown in the following table:
Name | Description |
---|---|
character_set_client | Character set used by MySQL client |
character_set_connection | Character set used when connecting to the database |
character_set_database | The character set used to create the database |
character_set_filesystem | The character set used by the MySQL server file system, the default value is binary, no conversion is performed |
character_set_results | The character set used when the database returns data to the client |
character_set_server | Used by the MySQL server It is recommended that the character set be managed by the system itself. Do not define it artificially. |
character_set_system | The character set used by the database system. The default value is utf8 and no setting is required. |
character_sets_dir | Character set installation directory |
When the characters are garbled, you don’t need to care about character_set_filesystem, character_set_system and character_sets_dir. 3 system variables that will not affect garbled characters.
In MySQL, the command and execution process to view the available character sets are as follows:
mysql> SHOW CHARACTER set; +----------+---------------------------------+---------------------+--------+ | Charset | Description | Default collation | Maxlen | +----------+---------------------------------+---------------------+--------+ | big5 | Big5 Traditional Chinese | big5_chinese_ci | 2 | | dec8 | DEC West European | dec8_swedish_ci | 1 | | cp850 | DOS West European | cp850_general_ci | 1 | | hp8 | HP West European | hp8_english_ci | 1 | | koi8r | KOI8-R Relcom Russian | koi8r_general_ci | 1 | | latin1 | cp1252 West European | latin1_swedish_ci | 1 | | latin2 | ISO 8859-2 Central European | latin2_general_ci | 1 | | swe7 | 7bit Swedish | swe7_swedish_ci | 1 | | ascii | US ASCII | ascii_general_ci | 1 | | ujis | EUC-JP Japanese | ujis_japanese_ci | 3 | | sjis | Shift-JIS Japanese | sjis_japanese_ci | 2 | | hebrew | ISO 8859-8 Hebrew | hebrew_general_ci | 1 | | tis620 | TIS620 Thai | tis620_thai_ci | 1 | | euckr | EUC-KR Korean | euckr_korean_ci | 2 | | koi8u | KOI8-U Ukrainian | koi8u_general_ci | 1 | | gb2312 | GB2312 Simplified Chinese | gb2312_chinese_ci | 2 | | greek | ISO 8859-7 Greek | greek_general_ci | 1 | | cp1250 | Windows Central European | cp1250_general_ci | 1 | | gbk | GBK Simplified Chinese | gbk_chinese_ci | 2 | | latin5 | ISO 8859-9 Turkish | latin5_turkish_ci | 1 | | armscii8 | ARMSCII-8 Armenian | armscii8_general_ci | 1 | | utf8 | UTF-8 Unicode | utf8_general_ci | 3 | | ucs2 | UCS-2 Unicode | ucs2_general_ci | 2 | | cp866 | DOS Russian | cp866_general_ci | 1 | | keybcs2 | DOS Kamenicky Czech-Slovak | keybcs2_general_ci | 1 | | macce | Mac Central European | macce_general_ci | 1 | | macroman | Mac West European | macroman_general_ci | 1 | | cp852 | DOS Central European | cp852_general_ci | 1 | | latin7 | ISO 8859-13 Baltic | latin7_general_ci | 1 | | utf8mb4 | UTF-8 Unicode | utf8mb4_general_ci | 4 | | cp1251 | Windows Cyrillic | cp1251_general_ci | 1 | | utf16 | UTF-16 Unicode | utf16_general_ci | 4 | | utf16le | UTF-16LE Unicode | utf16le_general_ci | 4 | | cp1256 | Windows Arabic | cp1256_general_ci | 1 | | cp1257 | Windows Baltic | cp1257_general_ci | 1 | | utf32 | UTF-32 Unicode | utf32_general_ci | 4 | | binary | Binary pseudo charset | binary | 1 | | geostd8 | GEOSTD8 Georgian | geostd8_general_ci | 1 | | cp932 | SJIS for Windows Japanese | cp932_japanese_ci | 2 | | eucjpms | UJIS for Windows Japanese | eucjpms_japanese_ci | 3 | | gb18030 | China National Standard GB18030 | gb18030_chinese_ci | 4 | +----------+---------------------------------+---------------------+--------+ 41 rows in set (0.02 sec)
Among them:
The first column (Charset ) is the character set name;
The second column (Description) is the character set description;
The third column (Default collation) is the character The default collation rules of the set;
The fourth column (Maxlen) indicates the maximum number of bytes occupied by a character in the character set.
Commonly used character sets are as follows:
latin1 supports Western European characters, Greek characters, etc.
gbk supports simplified Chinese characters.
big5 supports traditional Chinese characters.
utf8 supports characters from almost all countries.
The above is the detailed content of How to query character encoding in mysql5.5?. For more information, please follow other related articles on the PHP Chinese website!