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/ ...
随机推荐
- 基于impi zabbix监控r720 测试过程
1.F2进入服务器bios 修改network 使这台服务器能够被远程访问. 2.在远程的centos 7 服务器上安装 impitool工具包 #ipmitool -I lanplus -H X ...
- Read-Only Tables 只读表
Put a table into read-only mode,which prevents DDL or DML changes during table maintenance Put the ...
- k8s手动安装-1
1.组网master可以使用双网卡,一个外网网卡连接外网,并且做proxy server,一个host-only网卡和node连接. 新版vitualbox配置host-only需要在主机网络管理器中 ...
- 【leetcode】41. First Missing Positive
题目如下: 解题思路:这题看起来和[leetcode]448. Find All Numbers Disappeared in an Array很相似,但是有几点不同:一是本题的输入存在负数,二是没有 ...
- TPS、QPS和系统吞吐量的区别和理解
参考:https://blog.csdn.net/u010889616/article/details/83245695 一.QPS/TPSQPS:Queries Per Second意思是“每秒查询 ...
- JLRoutes笔记
1.在info.plist中添加 <key>CFBundleURLTypes</key> <array> <dict> <key>CFBun ...
- Docker Toolbox 学习教程【转载】
最近在研究虚拟化,容器和大数据,所以从Docker入手,下面介绍一下在Windows下怎么玩转Docker.Docker本身在Windows下有两个软件,一个就是Docker,另一个是Docker T ...
- php str_ireplace()函数 语法
php str_ireplace()函数 语法 作用:字符串替换操作,不区分大小写 语法:str_ireplace(find,replace,string,count)大理石平台规格 参数: 参数 描 ...
- CentOS 7.5 通过kubeadm部署k8s-1.15.0
kubeadm是Kubernetes官方提供的用于快速安装Kubernetes集群的工具,伴随Kubernetes每个版本的发布都会同步更新,kubeadm会对集群配置方面的一些实践做调整,通过实验k ...
- 【转】Django 基本命令
Django 基本命令 1. 新建一个 django project django-admin.py startproject project_name 特别是在 windows 上,如果报错,尝试用 ...
