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 ...
随机推荐
- servlet+jsp update修改页面的实现,整整搞了两个小时才搞定
package DAO; public class books { private int bid; private String bname; private int booksl; private ...
- usaco training 3.4.3 fence9 题解
Electric Fence题解 Don Piele In this problem, `lattice points' in the plane are points with integer co ...
- Mycat在MySQL主从模式(1主1从)下读写分离和及自动切换模式的验证
实验环境 两台Centos7 MySQL5.7.12 IP地址为:192.168.10.36 192.168.10.37 一台Centos7 Mycat IP地址为:192.168.10.31 一 ...
- ArcGisEngine图层操作(随笔,不全)
1.加载图层: 1.1 object.AddLayer(Layer[,toindex=0]) Layer表示ILayer对象,必选,toIndex参数表示图层索引(长整型),没需求可以忽略. 1.2 ...
- EntityManager 实例化方法
Configure the EntityManager via a persistence.xml file <persistence xmlns="http://java.sun.c ...
- C#.NET 中visual studio生成的.pdb/ .vshost.exe/ .vshost.exe.manifest文件是什么
pdb文件: 英文全称:Program Database File 中文全称:程序数据库 文件 Debug里的PDB是full,保存着调试和项目状态信息.有断言.堆栈检查等代码.可以对程序的调试配 ...
- 包装类、数组、string类浅析及练习
String s1 = "abc"; String s2 = "abc"; System.out.println(s1==s2); //返回true Strin ...
- SQLServer中的执行计划缓存由于长时间缓存对性能造成的干扰
本文出处:http://www.cnblogs.com/wy123/p/7190785.html (保留出处并非什么原创作品权利,本人拙作还远远达不到,仅仅是为了链接到原文,因为后续对可能存在的一些错 ...
- [C++]智能指针的实现与使用
智能指针 智能指针是当我们在使用对象时,有时会把对象的内存分配在堆上忘记释放,导致内存泄露,并且当多个指针共享同一个对象的内存时,容易出现重复释放内存,导致错误. 我们针对所需要共享的对象,手动完成一 ...
- Work 1(导游类)(2017.06.27)