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;
修改后如下
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步