ERROR 1366 (HY000): Incorrect string value: ' \XE4\XBD\XA0\XE5\XA5\XBD ' for column ' name ' at row 1

Source: Internet
Author: User
One: Problem description

mysql> INSERT INTO T2 (id,name) VALUES (1, ' hello ');

ERROR 1366 (HY000): Incorrect string value: ' \XE4\XBD\XA0\XE5\XA5\XBD ' for column ' name ' at row 1

Two: The cause of the error


The character set does not support Chinese.

Mysql> Show create table T2;
+-------+------------------------------------------------------------------------------------------------------ ------------------+
| Table | Create Table                                                                                                           |
+-------+------------------------------------------------------------------------------------------------------ ------------------+
| T2    | CREATE TABLE ' T2 ' (
  ' id ' int () default null,
  ' name ' char () default null
) Engine=innodb default Charset=la tin1 |
+-------+------------------------------------------------------------------------------------------------------ ------------------+
1 row in Set (0.00 sec)
The character set is Latin1, so the Chinese data cannot be inserted.

III: Solutions


You can change the table character set and the corresponding column character set to UTF8.


Mysql> ALTER TABLE T2 CharSet UTF8;
Query OK, 0 rows affected (0.05 sec) records:0 duplicates:0 warnings:0 mysql> Show create TABLE T2; +-------+------------------------------------------------------------------------------------------------------ -------------------------------------+
| Table |                                                                                                                              Create Table
| +-------+------------------------------------------------------------------------------------------------------ -------------------------------------+
| T2 | CREATE TABLE ' T2 ' (' id ' int () DEFAULT null, ' name ' char () CHARACTER SET latin1 DEFAULT null) Engine=innodb Defau
LT Charset=utf8 | +-------+------------------------------------------------------------------------------------------------------
-------------------------------------+ 1 row in Set (0.00 sec) mysql> inserts into T2 (Id,name) VALUES (2, ' hello '); ERROR 1366 (HY000): IncorRect string value: ' \XE4\XBD\XA0\XE5\XA5\XBD ' for column ' name ' at row 1 or not. This is because the table character set is Latin1, the character set of the column is not set, the default is the same as the table, it is also latin1, so you need to modify the character set of the column:
 mysql> ALTER TABLE T2 modify name char (a) CHARACTER SET UTF8 DEFAULT NULL;
Query OK, 1 row affected (2.04 sec) records:1 duplicates:0 warnings:0 mysql> Show create TABLE T2; +-------+------------------------------------------------------------------------------------------------------ ----------------+
| Table |
Create Table | +-------+------------------------------------------------------------------------------------------------------ ----------------+
| T2 |
CREATE TABLE ' T2 ' (' id ' int () default null, ' name ' char () default null) Engine=innodb default Charset=utf8 | +-------+------------------------------------------------------------------------------------------------------ ----------------+ 1 row in Set (0.00 sec) is now plugged in again and no longer complains. 
mysql> INSERT INTO T2 (id,name) VALUES (3, ' hello ');
Query OK, 1 row affected (0.04 sec)


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.