mysql> create table a (name varchar(32));
Query OK, 0 rows affected (0.50 sec)mysql> insert into a values ('aaaaaa');
Query OK, 1 row affected (0.03 sec)mysql> insert into a values ('妹妹美');
Query OK, 1 row affected (0.06 sec)mysql> select count(distinct name) from a;
+----------------------+
| count(distinct name) |
+----------------------+
| 1 |
+----------------------+
1 row in set (0.05 sec)mysql>高手看看,只是为什么?为什么'aaaaaa'等于'妹妹美'?我竟以为count出来应该是2.

解决方案 »

  1.   

    第2条记录插入失败,因为你的文字编码不对,要用set name utf8设置成utf-8编码来储存汉字。
      

  2.   


    mysql> select * from a;
    +--------+
    | name   |
    +--------+
    | aaaaaa |
    | 妹妹美 |
    +--------+
    2 rows in set (0.00 sec)mysql>查询结果显示确实有两条记录。第二条记录应该没有插入失败
      

  3.   

    mysql> set names utf8;
    Query OK, 0 rows affected (0.00 sec)mysql> insert into a values ('妹妹美');
    ERROR 1366 (HY000): Incorrect string value: '\xC3\xC3\xC3\xC3\xC3\xC0' for colum
    n 'name' at row 1
    mysql>在设置成utf8后,插入中文数据又有错了。
      

  4.   

    select count(distinct name) from a group by name;
      

  5.   

    gbk编码下是这样的了。有些读音有点相似的都会被认为同一个字。所以我喜欢用latin1
      

  6.   

    mysql> create table a (name varchar(32));
    Query OK, 0 rows affectedmysql> insert into a values ('aaaaaa');
    Query OK, 1 row affectedmysql> insert into a values ('妹妹美');
    Query OK, 1 row affectedmysql> select count(distinct name) from a;
    +----------------------+
    | count(distinct name) |
    +----------------------+
    |                    2 |
    +----------------------+
    1 row in setmysql> set names gbk;
    Query OK, 0 rows affectedmysql> select count(distinct name) from a;
    +----------------------+
    | count(distinct name) |
    +----------------------+
    |                    2 |
    +----------------------+
    1 row in setmysql> set names utf8;
    Query OK, 0 rows affectedmysql> select count(distinct name) from a;
    +----------------------+
    | count(distinct name) |
    +----------------------+
    |                    2 |
    +----------------------+
    1 row in setmysql> set names gb2312;
    Query OK, 0 rows affectedmysql> select count(distinct name) from a;
    +----------------------+
    | count(distinct name) |
    +----------------------+
    |                    2 |
    +----------------------+
    1 row in set
    mysql> select version();
    +---------------------+
    | version()           |
    +---------------------+
    | 5.0.22-community-nt |
    +---------------------+
    1 row in setmysql> 最后是我的版本,我觉得你的环境有问题,对于中文的编码可能性很大。
      

  7.   

    我的这个问题在mysql版也有所跟踪。
    http://topic.csdn.net/u/20100705/21/c101b33f-2abf-447e-a4e6-0e322834e99f.html?seed=1645605709&r=66769697#replyachor大家帮忙看看问题所在吧。想得头皮发麻了。恼火恼火
      

  8.   

    如果你导出的sql中没有乱码,那你的导出参数是正确的!
    导出的sql文件是ANSI的,你可用工具软件查看编码类型,也可用记事本打开并在“另存为”对话框中查看
    你可以用工具或自编程序将sql文件的编码转换成你的数据库要求的编码
      

  9.   

    字符编码类型改为gbk_bin
    注意后面的bin