1.具体场景

两张表分别为:

CREATE TABLE `tb_user` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '用户编号(自增字段)',
`userName` varchar(32) NOT NULL DEFAULT '' COMMENT '用户昵称',
# ...
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1DEFAULT CHARSET=utf8 COMMENT='用户表'; CREATE TABLE `tb_sms_message` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`tel` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '手机号',
# ...
PRIMARY KEY (`id`),
) ENGINE=InnoDB AUTO_INCREMENT=1DEFAULT CHARSET=utf8;

报错信息如下:

Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='

2.查询SQL

SELECT * FROM `tb_sms_message`
where tel not IN (select userName from tb_user);

3.原因分析

两个关联的字段的collate不一致,无法直接关联。

这里我们可以对字段的校对集转化为一致:

CONVERT(tel USING utf8) COLLATE utf8_general_ci

修改后的SQL:

SELECT * FROM `tb_sms_message`
where CONVERT(tel USING utf8) COLLATE utf8_general_ci not IN (select userName from tb_user);

网上搜了挺多的,但是真正提到我这个问题的解决方式:

http://www.cnblogs.com/mrma/p/3440992.html

MySQL查询时报错Illegal mix of collations的更多相关文章

  1. mysql 客户端连接报错Illegal mix of collations for operation

    服务端用的是utf-8,客户端工具打开表和视图是会报Illegal mix of collations for operation错误,经排查,可以采用以下语句解决 SET character_set ...

  2. mysql调用存储过程出现Illegal mix of collations错误

    执行sql语句正常 执行存储过程 异常 提示 Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMP ...

  3. myslq数据库用union all查询出现 #1271 - Illegal mix of collations for operation 'UNION'

    出现 #1271 - Illegal mix of collations for operation 'UNION' 的原因是两个字符编码不匹配造成的. 我遇到的是  utf8_general_ci ...

  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. 彻底解决phpcms v9升级后,文章发布出现: Mysql 1267错误:MySQL Error : Illegal mix of collations 解决办法

    彻底解决phpcms v9升级后,文章发布出现: MySQL Query : SELECT * FROM `withli_a`.`v9_keyword` WHERE `keyword` = '吼吼' ...

  6. 解决Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COER

    今天在用java与mysql数据库时发现Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COER ...

  7. Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci...

    最近刚接触mysql,今天用mysql插入中文字符的时候,程序报错“Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_g ...

  8. Illegal mix of collations for operation 'like' while searching with Ignited-Datatables

    Stack Overflow Questions Developer Jobs Tags Users   Log In Sign Up Join Stack Overflow to learn, sh ...

  9. MySQL replication illegal mix of collations

    MySQL replication case 一则 转载:http://www.vmcd.org/2013/09/mysql-replication-case-%E4%B8%80%E5%88%99/ ...

随机推荐

  1. alert(1) to win

    一. function escape(s) { return '<script>console.log("'+s+'");</script>'; } 两种思 ...

  2. Django登录(含随机生成图片验证码)注册实例

    登录,生成随机图片验证码 一.登录 - 随机生成图片验证码 1.随机生成验证码 Python随机生成图片验证码,需要使用PIL模块,安装方式如下: pip3 install pillow 1)创建图片 ...

  3. 用Jquery方法实现的简单下滑菜单效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. 新功能初探 | MySQL 8.0 Multi-Valued Indexes功能简述

    顾名思义,索引上对于同一个Primary key, 可以建立多个二级索引项,实际上已经对array类型的基础功能做了支持,并基于array来构建二级索引.这意味着该二级索引的记录数可以是多于聚集索引记 ...

  5. OC + RAC (十) 常用宏

    . RAC(TARGET, [KEYPATH, [NIL_VALUE]]) :用于给某个对象的某个属性绑定. // 只要文本框文字改变,就会修改label的文字 RAC(self.labelView, ...

  6. 5,Vector

    一,Vector简介 1,Vector 是矢量队列,它是JDK1.0版本添加的类. 2,Vector 继承了AbstractList,实现了List:所以,它是一个队列,支持相关的添加.删除.修改.遍 ...

  7. 选项卡jq

    1.无定时器 $(function(){$('.banner-point li').on('click',function(){$(this).addClass('active').siblings( ...

  8. 动态规划 List

    例题 #A 传纸条(Accepted)    #B 乘积最大 (Unaccepted)    #C 石子合并 (Accepted)    #D 加分二叉树 (Unaccepted)    #E 没有上 ...

  9. zhanghao

    账号:wx8b9ddd1c943ce95f 密码:fa72de9a1721849edc7f41f8a81019e5

  10. php 中 http_build_query用法

    http_build_query (PHP 5) http_build_query -- 生成 url-encoded 之后的请求字符串描述string http_build_query ( arra ...