MySQL插入中文时编码错误:ERROR 1366 (HY000): Incorrect string value: '' for column '' at row 1

转自:https://my.oschina.net/gwlCode/blog/3004454

插入数据时

insert into account values(null,'名字',5000);

提示如下错误

ERROR 1366 (HY000): Incorrect string value: '\xE5\x90\x8D\xE5\xAD\x97' for column 'name' at row 1

查看数据表编码

show create table account;

修改数据表编码

alter table account character set utf8;

查看修改后的编码

show create table account;

此时表编码已修改为utf8,但name仍未lantin1,插入数据仍会出现如上错误,需要修改字段编码

格式:alter table 表名 change 字段名 字段名 varchar(50) character set utf8 not null;

alter table account change name name varchar(50) character set utf8 not null;

修改后如下

猜你喜欢

转载自www.cnblogs.com/linwenbin/p/11448700.html