1. Chinese garbled characters occurred when using MySQL and PHP.
(1) Any Character Set supporting multi-byte encoding, such as gb2312, GBK, and utf8, can store Chinese characters. Of course, the number of Chinese Characters in gb2312 is much smaller than that in GBK, while in gb2312, GBK and so on can all be encoded in utf8
(2) run the show variables like 'character \ _ set \ _ % 'command to view the current character set settings:
Mysql> show variables like 'character \ _ set \ _ % '; + bytes + -------- + | variable_name | value | + bytes + -------- + | character_set_client | gb2312 | character_set_connection | gb2312 | character_set_database | gb2312 | bytes | binary | gb2312 | | character_set_server | Latin1 | character_set_system | utf8 | + ------------------------ + -------- + 7 rows in SET (0.02 Sec) (the character set here is gb2312)
|
There are two main settings for displaying Chinese garbled characters: character_set_connection and character_set_results,
If If your two settings do not support Chinese encoding, garbled characters may occur. Set character_set_results = GBK; then you can set Chinese encoding.
(3). Set names charset_name; you can also set all character sets of the client at one time.
2. In. NET and MySQL databases, I also encountered a situation where Chinese characters could not be displayed!
My solution is to add a character set charset = utf8 to the connection character;
<Shortettings> <add key = "conn" value = "Server = 127.0.0.1; userid = root; Password = test; database = game; Port = 3306; charset = utf8; "/> </appsettings>
|
3. If UTF-8 encoding is used in Python
In the create Data You must add the default Character Set utf8 collate utf8_general_ci
Otherwise, a message such as data too long for column is displayed when you enter Chinese characters!
Create Database test default Character Set utf8 collate utf8_general_ci
|