今天突然遇到插入中文失败的情况,如下:
ERROR 1366 (HY000): Incorrect string value: '\xE5\xB0\x8F\xE6\x9D\x8E' for column 'name' at row 1
经分析,数据库编码问题:
1、my.ini配置文件编码均已调整为UTF8。
2、安装完MySQL后有个数据库的名字叫test,就用了一下,也没在意编码(因为配置文件中已经设置好了),建了个测试表,如下:
create table inttest(
id int unsigned not null primary key comment '编号',
name varchar(30) not null comment '姓名',
age int not null comment '年龄'
);
插入数据:
insert into inttest values(1,'津津',11);
报错,如:ERROR 1366 (HY000): Incorrect string value: '\xE5\xB0\x8F\xE6\x9D\x8E' for column 'name' at row 1
然后去网上查资料时编码问题,一查test数据库的编码,查询语句如下:
a.进入t