MySQL replication illegal mix of collations
MySQL replication case 一则
转载:http://www.vmcd.org/2013/09/mysql-replication-case-%E4%B8%80%E5%88%99/
Posted by admin on September 10th, 2013
最近同事处理了一则mysql复制错误.发出来参考下
MYSQL同步出错,报错信息如下:
Last_Errno: 1267Last_Error: Error 'Illegal mix of collations (utf8_general_ci,COERCIBLE) and (latin1_swedish_ci,IMPLICIT) for operation 'concat'' on query. Default database: 'inshop_app'. Query: 'INSERT INTO inshop_app.app_sms_order_info (ORDER_CODE, ORDER_TIME, ORDER_AMOUNT, ORDER_CONTENT, BUY_NUM, ORDER_STATUS, MERCHANT_ID, CREATE_TIME, UPDATE_TIME, APP_TYPE, pay_time, remark) VALUES( NAME_CONST('my_order_code',_utf8'SBY130830010708_F0' COLLATE 'utf8_general_ci'),NOW(),'0','1次', NAME_CONST('my_sms_num',1125000),'1', NAME_CONST('my_merchant_id',10708),NOW(),NOW(),'2',NOW(),CONCAT ('钻展赠送:', NAME_CONST('my_sms_num',1125000)))' |
出错原因分析:
此SQL在Master上执行时是这样的
INSERT INTO inshop_app.app_sms_order_info (ORDER_CODE, ORDER_TIME, ORDER_AMOUNT, ORDER_CONTENT, BUY_NUM, ORDER_STATUS, MERCHANT_ID, CREATE_TIME, UPDATE_TIME, APP_TYPE, pay_time, remark) VALUES( 'SBY130830010708_F0',NOW(),'0','1次', 1125000,'1', 10708,NOW(),NOW(),'2',NOW(),CONCAT ('钻展赠送:', 1125000)) |
该SQL本身是没问题的,执行成功,但是MYSQL在记录BINLOG的时候,会对常量用NAME_CONST()函数进行“标识”
同步的报错就出现在这个地方
CONCAT ('钻展赠送:', NAME_CONST('my_sms_num',1125000)) |
其中,’钻展赠送:’是UTF8字符集,NAME_CONST(‘my_sms_num’,1125000)得到的数值型常量被自动转型为LATIN1字符集,外层的CONCAT()函数不支持二种不同字符集进行连接,于是报错
以下测试可验证此分析:
无NAME_CONST()函数标识常量时,即如同在Master上执行时,成功
09:29:06 inshop_app> select concat('钻展赠送',123);+----------------------------+| concat('钻展赠送',123) |+----------------------------+| 钻展赠送123 |+----------------------------+1 row in set (0.00 sec) |
有NAME_CONST()函数标识常量时,即如同在Slave上执行时,失败
09:25:17 inshop_app> select concat('钻展赠送',name_const('colname',123));ERROR 1267 (HY000): Illegal mix of collations (utf8_general_ci,COERCIBLE) and (latin1_swedish_ci,IMPLICIT) for operation 'concat' |
报错与同步是一样的错误
什么情况下MySQL会自动加上NAME_CONST函数
测试1: 直接insert
11:27:32 test> insert into lengzhenguo_mha(c3,c4) values(1,'a'),('2','b');Query OK, 2 rows affected (0.00 sec)Records: 2 Duplicates: 0 Warnings: 0 |
BINLOG中的内容
#130909 11:28:35 server id 2009 end_log_pos 469 Query thread_id=10 exec_time=0 error_code=0SET TIMESTAMP=1378697315/*!*/;insert into lengzhenguo_mha(c3,c4) values(1,'a'),('2','b')/*!*/; |
测试2: 简单的存储过程
13:16:42 test> create procedure p_test() -> begin -> insert into lengzhenguo_mha(c3,c4) values(10,'abc'),('20','xyz'); -> commit; -> end -> $Query OK, 0 rows affected (0.00 sec)13:17:38 test> call p_test();Query OK, 0 rows affected (0.00 sec) |
BINLOG中的内容
#130909 13:18:21 server id 2009 end_log_pos 328 Query thread_id=12 exec_time=0 error_code=0use `test`/*!*/;SET TIMESTAMP=1378703901/*!*/;insert into lengzhenguo_mha(c3,c4) values(10,'abc'),('20','xyz')/*!*/; |
测试3:带参数的存储过程 类似bind value
13:22:43 test> CREATE procedure p_test_2 (i bigint, j varchar(30)) -> begin -> insert into lengzhenguo_mha(c3,c4) values(i,j); -> commit; -> end -> $Query OK, 0 rows affected (0.00 sec)13:23:16 test> call p_test_2(100,'dba');Query OK, 0 rows affected (0.00 sec)13:25:10 test> call p_test_2('500','dba');Query OK, 0 rows affected (0.00 sec) |
BINLOG中的内容
#130909 13:23:32 server id 2009 end_log_pos 612 Query thread_id=12 exec_time=0 error_code=0
SET TIMESTAMP=1378704212/*!*/;insert into lengzhenguo_mha(c3,c4) values( NAME_CONST('i',100), NAME_CONST('j',_latin1'dba' COLLATE 'latin1_swedish_ci'))/*!*/;#130909 13:25:15 server id 2009 end_log_pos 1226 Query thread_id=12 exec_time=0 error_code=0SET TIMESTAMP=1378704315/*!*/;insert into lengzhenguo_mha(c3,c4) values( NAME_CONST('i',500), NAME_CONST('j',_latin1'dba' COLLATE 'latin1_swedish_ci'))/*!*/; |
注意:’500′在写入Binlog时,已经被转换成数值型了
目前已知的解决方法:
方法1:不要直接使用数值,直接给予字符串,建议使用此方法
09:25:27 inshop_app> select concat('钻展赠送',name_const('colname','123'));+----------------------------------------------------+| concat('钻展赠送',name_const('colname','123')) |+----------------------------------------------------+| 钻展赠送123 |+----------------------------------------------------+1 row in set (0.00 sec) |
注意:这里的123加引号,字符串~
方法2:先进行类型转换
09:56:32 inshop_app> select concat('钻展赠送',convert(name_const('colname',123) using utf8));+----------------------------------------------------------------------+| concat('钻展赠送',convert(name_const('colname',123) using utf8)) |+----------------------------------------------------------------------+| 钻展赠送123 |+----------------------------------------------------------------------+1 row in set (0.00 sec) |
MySQL replication illegal mix of collations的更多相关文章
- 彻底解决phpcms v9升级后,文章发布出现: Mysql 1267错误:MySQL Error : Illegal mix of collations 解决办法
彻底解决phpcms v9升级后,文章发布出现: MySQL Query : SELECT * FROM `withli_a`.`v9_keyword` WHERE `keyword` = '吼吼' ...
- MySQL Error: Illegal mix of collations for operation 'concat'
在使用concat连接字符串时出现错误:MySQL Error: Illegal mix of collations for operation 'concat' 原因:字段操作默认为UTF8的编码, ...
- 【MySQL】Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and ...
线上遇到这个问题,详细信息如下: SQL state [HY000]; error code [1267]; Illegal mix of collations (utf8mb4_general_ci ...
- mysql提示:Illegal mix of collations for operation ‘UNION’
http://www.111cn.net/database/mysql/56096.htm show variables like "%char%"; show variables ...
- 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 ...
- mysql调用存储过程出现Illegal mix of collations错误
执行sql语句正常 执行存储过程 异常 提示 Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMP ...
- mysql 客户端连接报错Illegal mix of collations for operation
服务端用的是utf-8,客户端工具打开表和视图是会报Illegal mix of collations for operation错误,经排查,可以采用以下语句解决 SET character_set ...
- java.sql.SQLException: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' 异常处理,及MySQL数据库编码设置
java.sql.SQLException: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,C ...
- 【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 ...
随机推荐
- mybatis学习笔记(二)-- 使用mybatisUtil工具类体验基于xml和注解实现
项目结构 基础入门可参考:mybatis学习笔记(一)-- 简单入门(附测试Demo详细过程) 开始体验 1.新建项目,新建类MybatisUtil.java,路径:src/util/Mybatis ...
- js如何获取样式?
在某个项目中,我们经常会需要来获取某个元素的样式,比如说获取一个div的color:这样,新的问出现了, var style = box.style.width;console.log(style); ...
- 【ALB学习笔记】基于.NET环境的高频RFID卡读写设备的基本操作案例
基于.NET环境的高频RFID卡读写设备的基本操作案例 广东职业技术学院 欧浩源 1.引言 RFID高频卡在我们的日常生活中随处可见,是物联网应用中不可或缺的一个重要部分,也是全国职业院校技能大赛& ...
- HashMap的存储原理
HashMap是java中相当重要的数据结构,使用HashMap的场景非常之多,因此,了解HashMap实现的过程和原理,是非常有必要的,在一些面试中也会经常被问到.好了,我们赶紧来研究java内部是 ...
- 阅读MDN文档之布局(四)
Introducing positioning Static positioning Relative positioning Introducing top, bottom, left and ri ...
- Mybatis-多对多
先说一下需求: 在页面上显示数据库中的所有图书,显示图书的同时,显示出该图书所属的类别(这里一本书可能同时属于多个类别) 测试环境:MySQL.MyEclipse 创建表: 笔者这里使用 中间表 连接 ...
- 说说BroadcastReceiver和ContentProvider
上一篇说了Activity,Fragment和Service,今天来说说四大组件中的另外两个吧. BroadcastReceiver: 广播在实际开发中非常有用,是各个组件间通讯的利器.广播接收器分为 ...
- 为何你跟着滴滴D8级前端大神撸代码,技术却依旧原地踏步?
引子 听说最近有很多小伙伴,热衷于在慕课网上学习各种前端实战教程,并以完成项目为奋斗目标.比如本文接下来要提到的<Vue2.0高级实战之开发移动端音乐App>,这门课程的传授者是来自滴滴D ...
- UglyNumber - 找“丑数”
uglynumber的定义是只能被1,2,3,5整除的数 规定1是第一个uglynumber:以此类推,1 2 3 4 5 6 8 9 10 12 15 16 18 20 24 25 27 30 32 ...
- Codeforces_617E: XOR and Favorite Number(莫队算法)
题目链接 题意大致是说,给出一个长为n(n<=1e5)的数组,给定一个k(k<=1e6),给出m(m<=1e5)个询问,每组询问中回答 从a_l到a_r有多少个连续的子序列满足异或和 ...