我在mysql 中建了个表,用下面的insert 插入数据时会也错,请指教:
建表如下:
create table teacher(
id int(5) auto_increment not null primary key,
name char(128) not null
);
有错的插入方法如下:
insert into teacher values(Null,encode('il','df'));
insert into teacher values(NULL,encode('i','df'));错误:incorrect string value: '\xc0' for column 'name' at row 1如果这样插入就不会有错:
insert into teacher values(NULL,encode('somevalue','somepass'));为什么呢?
请指教,thanks

解决方案 »

  1.   

    字符集的问题mysql> select charset(encode('il','df'));
    +----------------------------+
    | charset(encode('il','df')) |
    +----------------------------+
    | binary                     |
    +----------------------------+
    1 row in set (0.00 sec)mysql>
    mysql> create table teacher(
        ->  id int(5) auto_increment not null primary key,
        ->  name char(128) not null
        -> ) DEFAULT CHARSET=utf8;
    Query OK, 0 rows affected (0.09 sec)mysql> insert into teacher values(Null,encode('il','df'));
    ERROR 1366 (HY000): Incorrect string value: '\xC0"' for column 'name' at row 1mysql> alter table teacher MODIFY `name` char(128) CHARACTER SET binary;
    Query OK, 0 rows affected (0.14 sec)
    Records: 0  Duplicates: 0  Warnings: 0mysql>
    mysql> insert into teacher values(Null, encode('il','df'));
    Query OK, 1 row affected (0.06 sec)mysql>