解决mysql插入中文字符报错的问题ERROR 1366 (HY000): Incorrect string value: '\xE5\xB0\x8F\xE6\x98\x8E' for column 'name' at row 1

时间:2022-05-06 22:40:14

报错内容:

mysql> insert into person values (1,22,'小明');
ERROR 1366 (HY000): Incorrect string value: '\xE5\xB0\x8F\xE6\x98\x8E' for column 'name' at row 1

 

解决方法:

1、查看建表语句

解决mysql插入中文字符报错的问题ERROR 1366 (HY000): Incorrect string value: '\xE5\xB0\x8F\xE6\x98\x8E' for column 'name' at row 1

 

2、表字符集修改,chartset为utf8

alter table person default character set utf8;

解决mysql插入中文字符报错的问题ERROR 1366 (HY000): Incorrect string value: '\xE5\xB0\x8F\xE6\x98\x8E' for column 'name' at row 1

解决mysql插入中文字符报错的问题ERROR 1366 (HY000): Incorrect string value: '\xE5\xB0\x8F\xE6\x98\x8E' for column 'name' at row 1

 

3、字段字符集修改

 alter table person change name name varchar(255) character set utf8;

解决mysql插入中文字符报错的问题ERROR 1366 (HY000): Incorrect string value: '\xE5\xB0\x8F\xE6\x98\x8E' for column 'name' at row 1

 

 再次插入数据:

mysql> insert into person values (1,22,'小明');
Query OK, 1 row affected (0.01 sec)

执行成功。