昨天把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 '= 的解决的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 数据库 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 ...

  4. 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 ...

  5. MySQL查询时报错Illegal mix of collations

    开发十年,就只剩下这套架构体系了! >>>   1.具体场景 两张表分别为: CREATE TABLE `tb_user` ( `id` bigint(20) NOT NULL AU ...

  6. 错误之Illegal mix of collations for operation 'like'

    内容来自博客:https://www.cnblogs.com/install/p/4417527.html MySQL Illegal mix of collations for operation ...

  7. 【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 ...

  8. 处理【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 ...

  9. 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 ...

随机推荐

  1. supermap iclient for js 标签专题图(服务端)

    <!DOCTYPE><html> <head> <meta http-equiv="Content-Type" content=" ...

  2. 国内好用的maven仓库,添加到本地nexus中

    速度快的maven仓库真的难找,国外网站很多被封了.前天在网上找,有人说阿里有个公开的,速度很快.确实很快! 我添加到本地nexus中,结果不能更新索引,我是这么添加的,如下: 这个地址在浏览器中能够 ...

  3. 深度技术GHOST WIN7系统32.64位j极速安装版 V2016年

    系统来自系统妈:http://www.xitongma.com 深度技术GHOST win7系统64位j极速安装版 V2016年3月 系统概述 深度技术ghost win7系统64位j极速安装版  版 ...

  4. Java打印九九乘法表

    package com.czgo; /** * 九九乘法表 * * @author AlanLee * */ public class Print99 { public static void mai ...

  5. jQuery与Zepto的异同

    一,同: Zepto最初是为移动端开发的库,是jQuery的轻量级替代品,因为它的API和jQuery相似,而文件更小.Zepto最大的优势是它的文件大小,只有8k多,是目前功能完备的库中最小的一个, ...

  6. Linux服务开机自启动设置

    Linux中也有类似于Window中的开机自启动服务,主要是通过chkconfig命令来设置.它主要用来更新(启动或停止)和查询系统服务的运行级信息.谨记chkconfig不是立即自动禁止或激活一个服 ...

  7. [经验]Textbox 做日志记录,

    private void Log(string msg) { txtLog.MaxLength = ; txtLog.AppendText(msg); } 起因:在Winform中用Textbox显示 ...

  8. Linux indent

    一.简介 indent可辨识C的原始代码文件,并加以格式化,以方便程序设计师阅读. 二.选项 http://www.runoob.com/linux/linux-comm-indent.html 三. ...

  9. ubuntu 12.04下安装openldap,slapd.conf找不到的解决方法

    https://help.ubuntu.com/12.04/serverguide/openldap-server.html ubuntu安装openldap经历了一系列挫折,网上找了半天资料都是一模 ...

  10. JustWe-WebServer Android上的Http服务器

    JustWe-WebServer Android手机上的Http服务器,可以用于内网/外网的数据交换. ps: 这个项目是JustWeEngine游戏框架中处理网络事件的一部分. 如何使用 设置as ...