给Mysql数据库插入一条数据的时候,报这个错误:
ERROR 1366 (HY000): Incorrect string value: '\xC8\xD9\xD2\xAB' for column 'name' at row 1
解决思路:是因为数据库编码的问题
解决办法:
一、查看表index_product的编码格式:
show create table index_product;
ERROR 1366 (HY000): Incorrect string value: '\xC8\xD9\xD2\xAB' for column 'name' at row 1可以看到表的编码显示latin1
二、表的编码改成utf8:
alter table index_product default character set utf8;
ERROR 1366 (HY000): Incorrect string value: '\xC8\xD9\xD2\xAB' for column 'name' at row 1
再次查看表的编码:
ERROR 1366 (HY000): Incorrect string value: '\xC8\xD9\xD2\xAB' for column 'name' at row 1
表的编码改变成utf8但是两个字段编码编码还是latin1;
试着看看能否插入数据:
ERROR 1366 (HY000): Incorrect string value: '\xC8\xD9\xD2\xAB' for column 'name' at row 1
显示字段name的插入值问题,现在把两个字段的编码改成Utf8试试
三、改变字段的编码:
1、name:
altert table index_product change name name varchar(50) character set utf8;
2、type:
alter tbale index_product change type type varchar(20) character set utf8;
现在看看字段编码:
ERROR 1366 (HY000): Incorrect string value: '\xC8\xD9\xD2\xAB' for column 'name' at row 1
最后尝试插入数据OK

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-23
  • 2022-12-23
  • 2021-04-29
  • 2021-08-17
  • 2021-11-14
  • 2021-10-06
猜你喜欢
  • 2022-12-23
  • 2021-05-27
  • 2021-06-24
  • 2022-01-11
  • 2022-01-11
  • 2021-07-30
相关资源
相似解决方案