表是这样建立的
create table test(
id int(10) not null auto_increment primary key,
name varchar(20) not null,
gender tinyint(1) default 0,
tel int(11) not null)default character set utf8;
我的第一条sql语句:
insert into test(name,gender,tel) values ("小明",1,1233888);
她提示ERROR 1366 (HY000): Incorrect string value:'/xC3/xF7' for column 'name' 1
但我这样时:
insert into test(name,gender,tel) values ("小",1,1233888);
和这样:
insert into test(name,gender,tel) values ("ming",1,1233888);
都插入成功。
但这时我:
insert into test(name,gender,tel) values ("明",1,1233888);
还是提示:ERROR 1366 (HY000): Incorrect string value:'/xC3/xF7' for column 'name' 1
这是怎么回事啊?求大牛指点。

解决方案 »

  1.   

    字符集问题show variables like 'char%'; 
      

  2.   

    insert into test(name,gender,tel) values ('小明',1,1233888);
    没问题啊
      

  3.   

    set names 'gbk';
    insert into test(name,gender,tel) values ("明",1,1233888);
    先设置一下字符集。http://blog.csdn.net/ACMAIN_CHM/archive/2009/05/12/4174186.aspx
    MySQL 中文显示乱码
      

  4.   

    谢谢,这个方法有效。但为什么还要用set names 'gbk';设定呢,我在建表时不是已经default character set utf8;了吗。
      

  5.   

    PS C:\Windows\system32> mysql -u fangzhaoguo -p
    Enter password: **********
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 3
    Server version: 5.5.19 MySQL Community Server (GPL)Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trade of Oracle Corporation and/or its
    affiliates. Other names may be trades of their respective
    owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> create database test;
    Query OK, 1 row affected (0.00 sec)mysql> use test;
    Database changed
    mysql> create table test(
        -> id int(10) not null auto_increment primary key,
        -> name varchar(20) not null,
        -> gender tinyint(1) default 0,
        -> tel int(11) not null)default character set utf8;
    Query OK, 0 rows affected (0.04 sec)mysql> insert into test(name,gender,tel) values ("小明",1,1233888);
    Query OK, 1 row affected (0.00 sec)mysql> insert into test(name,gender,tel) values ("小",1,1233888);
    Query OK, 1 row affected (0.00 sec)mysql> insert into test(name,gender,tel) values ("ming",1,1233888);
    Query OK, 1 row affected (0.00 sec)mysql> insert into test(name,gender,tel) values ("明",1,1233888);
    Query OK, 1 row affected (0.00 sec)mysql>没有任何问题啊
      

  6.   

    没有啊,
    insert into test(name,gender,tel) values ('小明',1,1233888);

    insert into test(name,gender,tel) values ("明",1,1233888);
    单引号和双引号都可以的。
      

  7.   


    mysql> SHOW TABLE STATUS FROM test \G;
    *************************** 1. row ***************************
               Name: test
             Engine: InnoDB
            Version: 10
         Row_format: Compact
               Rows: 4
     Avg_row_length: 4096
        Data_length: 16384
    Max_data_length: 0
       Index_length: 0
          Data_free: 7340032
     Auto_increment: 5
        Create_time: 2012-05-17 13:15:02
        Update_time: NULL
         Check_time: NULL
          Collation: utf8_general_ci
           Checksum: NULL
     Create_options:
            Comment:
    1 row in set (0.00 sec)ERROR:
    No query specifiedmysql> desc test;
    +--------+-------------+------+-----+---------+----------------+
    | Field  | Type        | Null | Key | Default | Extra          |
    +--------+-------------+------+-----+---------+----------------+
    | id     | int(10)     | NO   | PRI | NULL    | auto_increment |
    | name   | varchar(20) | NO   |     | NULL    |                |
    | gender | tinyint(1)  | YES  |     | 0       |                |
    | tel    | int(11)     | NO   |     | NULL    |                |
    +--------+-------------+------+-----+---------+----------------+
    4 rows in set (0.06 sec)我发现我说错了,所以后面附了帖子#7说明了一下
      

  8.   

    但我为什么每次插入前的先设定下:set names 'gbk';才可以的。不然还是不能插入汉字。
      

  9.   

    请问这个能改吗?我看到别人用是可以不输入这条命令啊。不然每次都得输入这条sql语句。
      

  10.   

    1. 中文,请确保 表中该字段的字符集为中文兼容:
     big5     | Big5 Traditional Chinese
     gb2312   | GB2312 Simplified Chinese
     gbk      | GBK Simplified Chinese
     utf8     | UTF-8 Unicode 2. 确保,联接参数与这个字段字符集一致,你可以用 set name 'charsetname';
     比如, set name 'gbk';
     这条命令会同时修改 character_set_client,character_set_connection,character_set_results
     (如果你的这架MySQL中都为中文,则你可以在my.ini或my.cnf中加上或修改这个参数, 参数文件修改后需重启MySQL服务)
    [mysql]
    default-character-set=gbk
    百度来的,我先下线了
      

  11.   

    呵呵,不好意思,刚回来。谢谢
    fangzhaoguo
    (古古_怪怪)