CMD Console insert failed solution when inserting MySQL database information in Chinese

Source: Internet
Author: User

Fault code:

mysql> INSERT INTO T1 (name,sex,age,address) VALUES (' Zhang San ', ' Male ', 11, ' Shahe '); ERROR 1366 (HY000): Incorrect string value: ' \xd5\xc5\xc8\xfd ' for column ' name ' at row 1


This failure is caused by data insertion failure due to inconsistent Chinese encoding.


In general, the MySQL database in the insertion of Chinese information error is not the case of Chinese code inconsistency. And currently supports the Chinese encoding format basically has utf-8,gbk,gb2312 three kinds, but the database, the JSP page, the console, the Java code and so on the place to be possible the code consistent, otherwise may bring the unnecessary trouble.


By looking, I found that my database encoding format is: Utf-8, as follows:

[Mysql]default-character-set=utf8


This information is in the MySQL installation directory of the My.ini file, in my case, that is: C:\Program files\mysql\mysql Server 5.5 under the My.ini.


The encoding format for our console is: GBK, as shown in:


The console is opened by Start, run, enter CMD in the Run window, and click Enter.


Because the console and MySQL Chinese encoding format is inconsistent, which results in Chinese data cannot be inserted successfully, the solution is to unify its encoding format, because the console encoding format can not be set, so we only change the database encoding format, at this time we will be the database encoding format also changed to GBK.


That is, the utf-8 in the My.ini file is changed to GBK, the code is as follows:

[MYSQL]DEFAULT-CHARACTER-SET=GBK

At this point, restart the MySQL server, and then insert the Chinese data, the result of the operation is as follows:

mysql> INSERT INTO T1 (name,sex,age,address) VALUES (' Zhang San ', ' Male ', 11, ' Shahe '); Query OK, 1 row affected (0.05 sec)







CMD Console insert failed solution when inserting MySQL database information in Chinese

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.