MySQL查询时报错Illegal mix of collations
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的更多相关文章
- mysql 客户端连接报错Illegal mix of collations for operation
服务端用的是utf-8,客户端工具打开表和视图是会报Illegal mix of collations for operation错误,经排查,可以采用以下语句解决 SET character_set ...
- mysql调用存储过程出现Illegal mix of collations错误
执行sql语句正常 执行存储过程 异常 提示 Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMP ...
- myslq数据库用union all查询出现 #1271 - Illegal mix of collations for operation 'UNION'
出现 #1271 - Illegal mix of collations for operation 'UNION' 的原因是两个字符编码不匹配造成的. 我遇到的是 utf8_general_ci ...
- 【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;
- 彻底解决phpcms v9升级后,文章发布出现: Mysql 1267错误:MySQL Error : Illegal mix of collations 解决办法
彻底解决phpcms v9升级后,文章发布出现: MySQL Query : SELECT * FROM `withli_a`.`v9_keyword` WHERE `keyword` = '吼吼' ...
- 解决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 ...
- 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 ...
- 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 ...
- MySQL replication illegal mix of collations
MySQL replication case 一则 转载:http://www.vmcd.org/2013/09/mysql-replication-case-%E4%B8%80%E5%88%99/ ...
随机推荐
- 为按钮绑定实现js跳转
页面代码 <button type="button" class="btn btn-xs btn-info" id="add" nam ...
- hdu 6044 : Limited Permutation (2017 多校第一场 1012) 【输入挂 组合数学】
题目链接 参考博客: http://blog.csdn.net/jinglinxiao/article/details/76165353 http://blog.csdn.net/qq_3175920 ...
- Python实例教程
转自:http://codingdict.com/article/9026 Python 100例-01 题目: 输有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数? Python 1 ...
- rk3328编译Linux固件
一.编译 Linux 固件 这一章将介绍编译 ROC-RK3328-CC Linux 固件的整个流程. 1.1 准备工作 Linux 固件在如下的环境中编译: Ubuntu 16.04 amd64 安 ...
- 笨办法学Python(learn python the hard way)--练习程序1-10
下面是当初看这本书时按照书中的代码做的练习,一行一行敲下来的,都已经试运行过,没有错误(基于python3),练习1-练习10 #ex1.py 1 #print("Hello world!& ...
- HTTP请求时候总是设置的两个参数ConnectionTimeOut和SocketTimeOut
在HTTP请求时候总是设置两个参数,就是连接超时和Socket超时 public static final String SO_TIMEOUT = "http.socket.timeout& ...
- form表单action带参数传递
form表单action带参数传递function submit(){ var u = document.forms[0].elements["user"].value; do ...
- PHP Trait特性
php类的单继承性,无法同时从两个基类中继承属性和方法,为了解决这个问题,使用Trait特性解决. Trait是一种代码复用技术,为PHP的单继承限制提供了一套灵活的代码复用机制. 用法:通过在类中使 ...
- ArayList的一些常用法<一> 转
转:http://yy.azj.blog.163.com/blog/static/18508700320122893451389/ import java.util.ArrayList; import ...
- (转)Hyper-v 安装CentOS 7 (其他虚拟机一样参考)
转:https://www.cnblogs.com/dunitian/p/4976077.html 平台之大势何人能挡? 带着你的Net飞奔吧!http://www.cnblogs.com/dunit ...
