ERROR 1366 (HY000): Incorrect string value: '\xD6\xD0\xCE\xC4' for column XXX at row 1

时间:2023-02-04 17:09:20

本错误为:该列的插入格式有误

修改该表中该列的字符集为utf-8



网上办法:

)不能插入中文解决办法:

向表中插入中文然后有错误。

  mysql> insert into users values(88,'中文');
  ERROR 1366 (HY000): Incorrect string value: '\xD6\xD0\xCE\xC4' for column 'usern
  ame' at row 1
  mysql> insert into users values(88,'中文');
  ERROR 1366 (HY000): Incorrect string value: '\xD6\xD0\xCE\xC4' for column 'usern
  ame' at row 1

  还要更改users表的username的字符集。
  mysql> alter table users modify username char(20) character set gbk;
  ERROR 1366 (HY000): Incorrect string value: '\xC0\xEE\xCB\xC4' for column 'usern
  ame' at row 1
  mysql> alter table users modify username char(20) character set gbk;
  ERROR 1366 (HY000): Incorrect string value: '\xC0\xEE\xCB\xC4' for column 'usern
  ame' at row 1

  因为表中已经有数据,所以更改username字符集的操作没有成功
  清空users表中的数据
  mysql> truncate table users;
  Query OK, 3 rows affected (0.01 sec)

  从新更改user表中username的字符集
  mysql> alter table users modify username char(20) character set gbk;
  Query OK, 0 rows affected (0.06 sec)
  Records: 0 Duplicates: 0 Warnings: 0

  这时再插入中文字符,插入成功。
  mysql> insert into users values(88,'中文');
  Query OK, 1 row affected (0.01 sec)

  mysql> select * from users;
  +--------+----------+
  | userid | username |
  +--------+----------+
  | 88 | 中文 |
  +--------+----------+
  1 row in set (0.00 sec)