MySQL Chinese garbled Problem Solution

Source: Internet
Author: User


Solve the MySQL classic problem of Chinese garbled MYSQL: (ERROR 1366 (HY000): Incorrect string value: '\ xD5 \ xD4' for column 'name' at row 1) there are a lot of posts on the Internet to solve Chinese Garbled text, basically speaking about modifying % MYSQL_DIR %/my. ini default-character-set = gbk or something I have tried, it does not work. (maybe I didn't handle it in place.) The following is the result I have been pondering for a long time. I don't know if it is worth advocating, but the goal is definitely achieved: log on to mysql ---> enter the corresponding database ---> enter the command: show variables like '% char %'; get: www.2cto.com + bytes + | Variable_name | Value | + bytes + | bytes utf8 | character_set_connection utf8 | character_set_database latin1 | bytes binary | bytes utf8 | bytes utf8 | bytes utf8 | bytes D: \ MySQL \ share \ charsets \ + -------------------------- +
If the above situation occurs, you need to change the database encoding: two methods, one is done at a time, the second is only valid for the current connection, disconnect, restore the status before the change method 1: alter database name charset utf8; Method 2: set character_set_database = utf8; Use the command: show variables like '% char % '; + bytes + | Variable_name | Value | + bytes + | bytes utf8 | character_set_connection utf8 www.2cto.com | character_set_database utf8 | bytes binary | bytes utf8 | bytes utf8 | bytes utf8 | bytes D: \ MySQL \ share \ charsets \ + -------------------------- +
At this time, the encoding is consistent. However, if you insert Chinese characters into a table in the database, ERROR 1366 (HY000) ---> set character_set_client = gbk is still reported; set the encoding received during insertion to GBK, so that Chinese characters can be inserted, but the query results are still garbled, and then change one place: ---> set character_set_results = gbk; encode the output result as GBK. Note: these settings are only related to the current connection and are disconnected. These settings restore the default database settings. Therefore, if needed, you have to set each connection! In addition, the ERROR 1366 (HY000) ERROR occurs mainly in the console (cmd/Black window) When an SQL statement is executed to insert a Chinese character, the mysql-front software will not report a character problem during insertion, java connects to the database through JDBC and executes executeUpdate ("insert statement"). Data can be inserted successfully in Chinese and no error is reported!
PHP solves the garbled problem by adding mysql_query ("set names 'gbk'") after connection! For example, $ conn = mysql_connect ("localhost", "root", ""); mysql_query ("set names 'gbk'"); author Jacy liang

Related Article

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.