Error: Illegal mix of collations (gbk_chinese_c...

先说解决的办法,以后再研究原因:

第一种解决办法:

修改sql语句为如下格式:
    $sql="select * from {$tablepre}members where nickname='".$nickname."'";    修改为
    $sql="select * from {$tablepre}members where nickname=binary('".$nickname."')";   

第二种方法:

修改数据库的字符集。我没有用过这个方法,但是感觉上应该是可以的。


如果MySQL数据库已经安装好,可以使用下列SQL命令查看MySQL当前的字符集设置:
mysql> SHOW VARIABLES LIKE 'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
7 rows in set (0.00 sec)

mysql> SHOW VARIABLES LIKE 'collation_%';
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | latin1_swedish_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.00 sec)

依次执行:

set character_set_client =gb2312;

set character_set_connection =gb2312;

set character_set_database =gb2312;

set character_set_results =gb2312;

set character_set_server =gb2312;

set character_set_system =gb2312; --此处utf-8也可以

然后执行:

SET collation_server = gb2312_chinese_ci


SET collation_database = gb2312_chinese_ci

SET collation_connection =gb2312_chinese_ci

执行完之后,请检查mysql下每个数据库,表,字段是否都是gb2312,不是则改过来,这样子就不会出现

Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (gb2312_chinese_ci,IMPLICIT) for operation '='这个错误了,网上有资料说要重装,其实根本就不必,改动其编码即可

第三种方法:网上看到的,先记录一下。

1.如果安装mysql的编码已不能更改,很多朋友是购买虚拟主机建立网站,无权更改MYSQL的安装编码,这一关我们可以跳过,因为只要后面的步聚正确,一样能解决乱码问题
2.修改数据库编码,如果是数据库编码不正确: 可以在phpmyadmin 执行如下命令: ALTER DATABASE `test` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin
以上命令就是将test数据库的编码设为utf8
3.修改表的编码:ALTER TABLE `category` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin
以上命令就是将一个表category的编码改为utf8
4.修改字段的编码:
ALTER TABLE `test` CHANGE `dd` `dd` VARCHAR( 45 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
以上命令就是将test表中 dd的字段编码改为utf8
5.如果是这种情况容易解决,只需检查下页面,修改源文件的charset即可
, //这个正确就无问题了
6.这种情况也是修改页面charset即可

你可能感兴趣的:(Error: Illegal mix of collations (gbk_chinese_c...)