mysql: Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '= 的解决
昨天把mysql里所有table的varchar字段的字符集,批量换成了utf8mb4/utf8mb4_unicode_ci ,以便能保存一些emoji火星文 , 结果有一个sql语句执行时,报错如下:
Illegalmixofcollations(utf8_unicode_ci,IMPLICIT)and(utf8_general_ci,IMPLICIT)foroperation '=
观察了一下,这个sql使用了一个自定义的function,这个函数的入口参数为varchar,类似如下:
CREATE FUNCTION `f_xxx`(
p_ref_type VARCHAR(50) ,
...
)
问题就在这里,把p_ref_type的参数类型改成:
CREATE FUNCTION `f_xxx`(
p_ref_type VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
...
)
就ok了。
当然,如果不想改function,还有一种一劳永逸的解决办法:(需要停机)
出错信息的意思是 utf8-unicode-cli与utf-general-cli 不能混用,可以用
show create function f_xxx\G 查看下结构,重点观察下最后几行:
... END
character_set_client: utf8mb4
collation_connection: utf8mb4_unicode_ci
Database Collation: utf8_general_ci
1 row in set (0.00 sec)
这里可以看出,collation_connnection 与 Database Collation所用的字符集不一致,要想办法弄成一致,可以再用:
SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%';
查看mysql的相关系统变量:
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
| collation_connection | utf8mb4_general_ci |
| collation_database | utf8mb4_general_ci |
| collation_server | utf8mb4_general_ci |
大概输出是这样的,注意最后3行,确认mysql实例的编码后,可以调整database的编码:
ALTER DATABASE `数据库名` character set utf8mb4 COLLATE utf8mb4_general_ci ;
考虑到,有些表或字段在创建时,可能也指定了其它编码,可以用:
./mysqldump -u用户名 -p -d --add-drop-table 数据库名 > 导出的文件名
注:为防止操作期间有人操作数据库,最好将所有应用暂时停机,保证操作期间db没人向其写入数据 。
导出表结构的sql,然后用文本编码工具,批量把指定字符集的字符串给批量清空,即:清除所有指定字符集的DDL语句,全部默认用database本身的字符集
接下来用
./mysqldump -u用户名 -p -t 数据库名 > 导出的文件名
导出所有数据
最后,干掉所有table,然后mysql命令行下
source 修改好以后的数据库表结构.sql
source 数据.sql
将所有表重建,然后导入数据,进行恢复,最终目标是将整个db,包括所有表及字段的字符集大换血了
mysql: Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '= 的解决的更多相关文章
- Mysql Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='
MySQL字符串比较bug: select * from table_a a left join table_b b on a.field_a = b.field_b error: Illegal ...
- Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '=
[SQL]SELECT username,password,toutiao_uidFROM pwdtab pLEFT JOIN toutiao_action_article aON p.toutiao ...
- 数据库 BUG:Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '=
在mysql5中遇到的问题: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) f ...
- 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查询时报错Illegal mix of collations
开发十年,就只剩下这套架构体系了! >>> 1.具体场景 两张表分别为: CREATE TABLE `tb_user` ( `id` bigint(20) NOT NULL AU ...
- 错误之Illegal mix of collations for operation 'like'
内容来自博客:https://www.cnblogs.com/install/p/4417527.html MySQL Illegal mix of collations for operation ...
- 【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 ...
- 处理【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 ...
- 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 ...
随机推荐
- Lind.DDD.Events事件总线~自动化注册
回到目录 让大叔兴奋的自动化注册 对于领域事件之前说过,在程序启动时订阅(注册)一些事件处理程序,然后在程序的具体位置去发布(触发)它,这是传统的pub/sub模式的体现,当然也没有什么问题,为了让它 ...
- artTemplate模板引擎学习实战
在我的一篇关于智能搜索框异步加载数据的文章中,有博友给我留言,认为我手写字符串拼接效率过低,容易出错.在经过一段时间的摸索和学习之后,发现现在拼接字符串的方法都不在是自己去书写了,而是使用Javasc ...
- iOS 真机测试 App installation failed
真机测试的过程中,出现这种Bug This application's application-identifier entitlement does not match that of the in ...
- Linux学习心得之 Linux下ant安装与使用
作者:枫雪庭 出处:http://www.cnblogs.com/FengXueTing-px/ 欢迎转载 Linux学习心得之 Linux下ant安装与使用 1. 前言2. ant安装3. 简单的a ...
- Linux0.11内核--内存管理之1.初始化
[版权所有,转载请注明出处.出处:http://www.cnblogs.com/joey-hua/p/5597705.html ] Linux内核因为使用了内存分页机制,所以相对来说好理解些.因为内存 ...
- 在TableView上添加悬浮按钮
如果直接在TableVIewController上贴Button的话会导致这个会随之滚动,下面解决在TableView上实现位置固定悬浮按钮的两种方法: 1.在view上贴tableView,然后将悬 ...
- IOS开发基础知识--碎片25
1:使用@protocol实现delegate和datasource模式 #import <UIKit/UIKit.h> @protocol MyViewDataSource,MyView ...
- iOS 10 都有什么改变?
iOS 10 都有什么改变? 看这一个贴就够了 最全面的试用 苹果在 WWDC 2016 发布会上正式发布了 iOS 10 操作系统,iOS 与 macOS.tvOS 和 watchOS 构建了苹果四 ...
- #研发解决方案介绍#基于ES的搜索+筛选+排序解决方案
郑昀 基于胡耀华和王超的设计文档 最后更新于2014/12/3 关键词:ElasticSearch.Lucene.solr.搜索.facet.高可用.可伸缩.mongodb.SearchHub.商品中 ...
- 不同环境下文件上传Uncaught SyntaxError: Unexpected end of input
很奇怪的问题,相同的代码和相同的数据,在两台linux服务器上执行文件上传,一台正常上传,一台在ftl页面 报:Uncaught SyntaxError: Unexpected end of inpu ...