在操作MySQL数据库时,报“

error code [1267];

Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation 'like'

对于常见的乱码问题,有的在数据库本身已经为gbk或gb2312时候,但是查询出来却是乱码,这是因为mysql在连接的过程中还有道编码,因此将连接的编码设为gb2312或utf-8

即可,如:

jdbc:mysql://localhost:3306/ipanel?useUnicode=true&characterEncoding=UTF-8

hibernate和jdbc的参数设置是不一样,但大体相同,网上类似的资料很多。

最重要的是这个问题:

Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (gb2312_chinese_ci,IMPLICIT) for operation '='

相信有很多人碰到,意思是说字符编码不一样,不能进行比较,也就是说数据库内部的编码都不一样,有的数据是

gbk_chinese_ci,有的数据是gb2312_chinese_ci,因此解决此问题的核心就是将数据库所有的编码进行统一。

解决方案一:暂时
//恶心的gb2312不能使用,需要转utf-8再继续
$where = $where . iconv("gb2312","utf-8"," and USER_NAME='" . $uname . "'");

解决方案二:

进入命令行模式,

如果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 '='这个错误了,网上有资料说要重装,其实根本就不必,改动其编码即可

*****************************

PHP5.2+MYSQL5.1+APACHE2.29  IE6,firefor2,firefox3 
      PHP网页向MYSQL数据库插入记录时出现如下问题。 
Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (latin1_swedish_ci,COERCIBLE) for operation '='        ???????????? 
解决方法:1.注意PHP网站  charset=UTF-8" 
              <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
                2.数据库连接设置为 utf8编码

<?php 
# FileName="Connection_php_mysql.htm" 
# Type="MYSQL" 
# HTTP="true" 
$hostname_member = "localhost"; 
$database_member = "member"; 
$username_member = "root"; 
$password_member = "123456"; 
$member = mysql_pconnect($hostname_member, $username_member, $password_member) or trigger_error(mysql_error(),E_USER_ERROR); 
mysql_query("set names gbk"); 
?> 
          请修改为  mysql_query("set names utf8"); 
          中文问题花去一天时间,请注意php和MYSQL编码发送相同问题。与MYSQL数据库编码无关 
          有问题联系

SQLSTATE[HY000]: General error: 1267 Illegal mix of collations (utf8_general_ci,IMPLICIT) and (gb2312_chinese_ci,COERCIBLE) for operation '='的更多相关文章

  1. 【mysql】【转发】[Err]1267 - Illegal mix of collations(utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,I

    [Err]1267 - Illegal mix of collations(utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for o ...

  2. [Err]1267 - Illegal mix of collations(utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation ‘=’

    SELECT * FROM table_a a  where a.id NOT IN (SELECT b.id FROM table_b  b); 先将两个数据表的编码统一,如果table_a的编码为 ...

  3. mysql字符集问题 错误代码: 1267 Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_croatian_ci,IMPLICIT) for operation '='

    一般是多表或跨库表查询导致出现的问题,其原因是两张表的字符集不一样导致的,那为什么两张表的字符集会不一样?这是由于架构师或者开发人员在建表的时候不小心选错字符集的原因导致的. 那好我们把两张表(或两个 ...

  4. 【mysql】[Err]1267 - Illegal mix of collations(utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation ‘=

    ALTER TABLE table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;

  5. Django的admin管理系统写入中文出错的解决方法/1267 Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation ‘locate’

    Django的admin管理系统写入中文出错的解决方法 解决错误: 1267  Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and ( ...

  6. Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLIC

    在mysql5中遇到的问题: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) f ...

  7. 处理【Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operatio】

    错误详情]:{DAL:DAL05}{Host:192.168.100.158}Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf ...

  8. ERROR 1267 (HY000): Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '='

    多表查询出错,貌似是编码问题. 我比较的两个表的某个字段,设为查询条件,两个字段等于某个值,参照网上的某些论坛调用alter语句,但是依旧没有效果.最后直接拆分成两个条件,a.字段1=x值,b.字段2 ...

  9. 1267 - Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' | 1267 - Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (Latin,COERCIBL)

    select * FROM information_schema.columns WHERE table_schema = "databaseName" and collation ...

随机推荐

  1. js获取URL里的参数

    第一种 通过正则获取URL中指定的参数 /** * 获取指定的URL参数值 * URL:http://www.xxx.com/index?name=123 * 参数:param URL参数 * 调用方 ...

  2. spring aop使用,spring aop注解,Spring切面编程

    ================================ ©Copyright 蕃薯耀 2020-01-21 https://www.cnblogs.com/fanshuyao/ 一.第一步, ...

  3. mysql的优化(经典必看)

    1.选取最适用的字段属性 MySQL可以很好的支持大数据量的存取,但是一般说来,数据库中的表越小,在它上面执行的查询也就会越快.因此,在创建表的时候,为了获得更好的性能,我们可以将表中字段的宽度设得尽 ...

  4. join方法,wait()和sleep()

    join方法解释:方法x.join()的作用是使所属线程x 正常执行run()中的方法,而使得调用x.join()的线程处于无限期阻塞状态,等待x线程销毁后再继续执行线程z后面的代码. 1.方法joi ...

  5. Eclipse项目转到MyEclipse中出错

    原因如下. JDK的编译版本和JRE的运行版本不一致导致了这个问题. 在MyEclipse中,对项目进行Build path 逐一设置即可. 还有关于类型转换的问题,由于JDK版本的不一致,下载下来的 ...

  6. 构造和改变一个string的其他方法

    构造一个string的其他方法: 1string s1(cp, n),cp为c风格数组名或一个指向C风格数组的指针,则执行的操作为拷贝从cp开始包括cp在内的接下来n个字符给s1,n的默认值为size ...

  7. 【PAT甲级】1119 Pre- and Post-order Traversals (30分)(已知先序后序输出是否二叉树唯一并输出中序遍历)

    题意: 输入一个正整数N(<=30),接着输入两行N个正整数第一行为先序遍历,第二行为后续遍历.输出是否可以构造一棵唯一的二叉树并输出其中一颗二叉树的中序遍历. trick: 输出完毕中序遍历后 ...

  8. c#中的yield词法

    yield关键字的作用是将当前集合中的元素立即返回,实例: 通过断点可以看到,控制台每显示一个集合中的元素,都会到query方法中去取集合元素. 其实yield return是“语法糖”,其本质是生成 ...

  9. .Net中C# Dictionary 用法

    Dictionary提供快速的基于键值的元素查找. 结构是:Dictionary <[key] , [value] >,当你有很多元素的时候可以用它. 它包含在System.Collect ...

  10. 【转载】 __declspec(dllexport) 和__declspec(dllimport)

    转自:http://www.cppblog.com/Dutyboy/archive/2010/11/15/133699.html __declspec(dllexport)   __declspec( ...