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