Various garbled characters in the MySQL database and Their Solutions

Source: Internet
Author: User

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

         

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.