感谢大家。找到问题了,很猪头的问题。。。 用这段代码打印了下,就发现 database 是 latin1 的。之前一直看的是 mysql cli 里面的是 utf8 的。 然后悲剧的发现,perl 里面连的错误的 database 。。。。。。。。恰好里面都有一个这个表。。。
那个库里面的这个表的我需要的这个字段是 latin1 的,我刚才没发现问题前还试了别的字段,结果发现有的字段能用中文,有的不能,还在纳闷儿。。。这个库里面的这个表的字段有些是 utf8 的,有些是 latin1 的。。。日 再次感谢大家。。。 在 2010年7月7日 上午11:56,azure wang <[email protected]>写道: > use DBI; > my $dbh = DBI->connect("dbi:mysql:test:localhost:3306", "root", "123456", > > {RaiseError => 1, > mysql_enable_utf8 => 1, > mysql_auto_reconnect => 1} ); > $pstmt = $dbh->prepare("show variables like '%character_set%'"); > $pstmt->execute(); > while(my $row = $pstmt->fetchrow_arrayref){ > printf "%s,%s\n",$row->[0],$row->[1]; > } > > > character_set_client,utf8 > character_set_connection,utf8 > character_set_database,utf8 > character_set_filesystem,binary > character_set_results,utf8 > character_set_server,utf8 > character_set_system,utf8 > character_sets_dir,E:\MySQL\share\charsets\ > > 你看看你当前字符集的环境变量是什么。 > > > 在 2010年7月7日 上午11:49,azure wang <[email protected]>写道: > > Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and >> (utf8_general_ci,COERCIBLE) for operation '=' 是等号两边的字符集不一样 >> 显然等号左边就是字段的字符集是latin1_swedish_ci, 而有变输入的字符串是utf8_general_ci 问题应该在你的表。 >> >> 你把整个表结构导出SQL 然后发出来看看。 >> >> 在 2010年7月7日 上午11:26,Kaiwang Chen <[email protected]>写道: >> >> 字段上没设置,default 就按是表的设置吧。你那 where = '中文' 是怎么输进去的? >>> >>> 在 2010年7月7日 上午11:19,wd <[email protected]> 写道: >>> > 字段上面没看到有设置。只有表有。咋回事呢?奇怪。。。 >>> > >>> > 在 2010年7月7日 上午11:11,azure wang <[email protected]>写道: >>> >> >>> >> 把show create table xxx 看看 >>> >> >>> >> MySQL每个字段都可以设置字符集 看看每个字段的字符集是否正确。 >>> >> >>> >> >>> >> 在 2010年7月7日 上午11:09,wd <[email protected]>写道: >>> >>> >>> >>> 使用 dbi DBD::mysql 连 mysql, >>> >>> >>> >>> my $dbh = DBI->connect($dsn, $user, $password, >>> >>> {RaiseError => 1, >>> >>> mysql_enable_utf8 => 1, >>> >>> mysql_auto_reconnect => 1} ); >>> >>> >>> >>> 已经 enable 了 utf8,但是 sql 里面如果有 where xxx = '中文' 这样的语句就报错, >>> >>> >>> >>> DBD::mysql::db selectall_arrayref failed: Illegal mix of collations >>> >>> (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for >>> operation >>> >>> '=' at ./e.pl line 128. >>> >>> >>> >>> 尝试 $dbh->do('set names utf8') 没用,不过 set names latin1 就不报了,不过结果不对。。。 >>> >>> >>> >>> table 是 ENGINE=InnoDB DEFAULT CHARSET=utf8 >>> >>> >>> >>> 把那个 sql 打印出来,然后在 mysql cli 执行就没问题。这怎么弄?有人有经验没? >>> >>> >>> >>> -- >>> >>> 您收到此邮件是因为您订阅了 Google 网上论坛的"PerlChina Mongers 讨论组"论坛。 >>> >>> 要向此网上论坛发帖,请发送电子邮件至 [email protected]。 >>> >>> 要取消订阅此网上论坛,请发送电子邮件至 >>> >>> [email protected]<perlchina%[email protected]> >>> 。 >>> >>> 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN访问此网上论坛。 >>> >> >>> >> >>> >> >>> >> -- >>> >> Azure.Wang >>> >> >>> >> -- >>> >> 您收到此邮件是因为您订阅了 Google 网上论坛的"PerlChina Mongers 讨论组"论坛。 >>> >> 要向此网上论坛发帖,请发送电子邮件至 [email protected]。 >>> >> 要取消订阅此网上论坛,请发送电子邮件至 >>> >> [email protected]<perlchina%[email protected]> >>> 。 >>> >> 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。 >>> > >>> > -- >>> > 您收到此邮件是因为您订阅了 Google 网上论坛的"PerlChina Mongers 讨论组"论坛。 >>> > 要向此网上论坛发帖,请发送电子邮件至 [email protected]。 >>> > 要取消订阅此网上论坛,请发送电子邮件至 >>> > [email protected]<perlchina%[email protected]> >>> 。 >>> > 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。 >>> > >>> >>> -- >>> 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。 >>> 要向此网上论坛发帖,请发送电子邮件至 [email protected]。 >>> 要取消订阅此网上论坛,请发送电子邮件至 >>> [email protected]<perlchina%[email protected]> >>> 。 >>> 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。 >>> >>> >> >> >> -- >> Azure.Wang >> > > > > -- > Azure.Wang > > -- > 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。 > 要向此网上论坛发帖,请发送电子邮件至 [email protected]。 > 要取消订阅此网上论坛,请发送电子邮件至 > [email protected]<perlchina%[email protected]> > 。 > 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。 > -- 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。 要向此网上论坛发帖,请发送电子邮件至 [email protected]。 要取消订阅此网上论坛,请发送电子邮件至 [email protected]。 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。
