mysql解决[HY000][1366] Incorrect string value: '\xE4\xB8\xAD\xE6\x96\x87' for column 'title' at row 1

最近在玩django ORM操作,本地部署mysql之后,往库里插入中文时,总是报错,如图所示:

mysql解决[HY000][1366] Incorrect string value: '\xE4\xB8\xAD\xE6\x96\x87' for column 'title' at row 1

查找原因是因为插入的字符格式不正确,通过命令 show variables like "%character%";可以查看格式为:

mysql解决[HY000][1366] Incorrect string value: '\xE4\xB8\xAD\xE6\x96\x87' for column 'title' at row 1

需要改成我们utf8格式才可以插入中文,临时修改了一个表格式,通过命令:

alter table `tablename` convert to character set utf8;

修改当前表格式为utf8格式,这样当前表就可以插入中文 字段,测试结果为:

mysql解决[HY000][1366] Incorrect string value: '\xE4\xB8\xAD\xE6\x96\x87' for column 'title' at row 1