首页 > 代码库 > 【复制】【编码】MySQL复制中的编码问题

【复制】【编码】MySQL复制中的编码问题

 编码背景知识

Latin-1,全称ISO 8859-1 Latin 1 对ASCII的拉丁语扩展 向下兼容ASCII,其编码范围是0x00-0xFF,0x00-0x7F之间完全和ASCII一致,0x80-0x9F之间是控制字符,0xA0-0xFF之间是文字符号。

ASCII   没啥好说的 0x00 – 0x7f 地球人都会查表

GBK:查表 http://ff.163.com/newflyff/gbk-list/

UTF8编码:Unicode表的一种落地实现 (包括传输<大小端>,字节存储,解释等)

记住 : GBK 如果想转换成UTF8 , 是没有二进制规律的,一般都是通过 
GBK 查表  --à Unicode对应坑 -à 按照规则变成- : UTF8 。

Unicode:记住在Unicode字符表中,每种语言的每个文字都占了一个坑 。Unicode编码由两个字节(常用够了)或四个字节(甲骨文之类)来表示。

UNICODEUTF-8的转换就是

1 先确定编码所需要的UTF-8编码字节数

2 然后用UNICODE编码位从低位到高位依次按规则填入空位,不足的高位以0补充

 

1. 错误‘Incorrect string value: ‘\xE7\xB3\xBB\xE7\xBB\x9F...‘

Last_Errno: 1366Last_Error: Error Incorrect string value: \xE7\xB3\xBB\xE7\xBB\x9F... for column content at row 1 on query. Default database: ibank. Query: update bk_web_close set createTime=2014-06-14 14:30:30, updateTime=2014-08-14 21:02:31, version=8, content=<div>\r\n 系统升级中,请暂停使用。</div>\r\n, status=1 where id=1 and version=7

查看binlog:

update bk_web_close set createTime=2014-06-14 14:30:30, updateTime=2014-08-14 21:02:31, version=8, content=<div>\r\n <E7><B3><BB><E7><BB><9F><E5><8D><87><E7><BA><A7><E4><B8><AD><EF><BC><8C><E8><AF><B7><E6><9A><82><E5><81><9C><E4><BD><BF><E7><94><A8><E3><80><82></div>\r\n, status=1 where id=1 and version=7/*!*/;

 

2. 类似错误

Incorrect string value: \xB2\xE1 for column title at row 1 on query. Default database: db_puyitou. Query: update CM_NEWS set htmlstatus=1, htmlname=0x3230313430373237323435302E68746D, templateid=25, columnid=7, userid=0x61646D696E, subcolumnid=12, title=0xD7A2B2E1, keyword="", description="", source="", content=0x3C703E3C7370616E207374796C653D22464F4E542D46414D494C593A20CBCECCE52C53696D53756E3B20434F4C4F523A20233539353935393B20464F4E542D53495A453A2031347078223EA2D9203C2F7370616E3E3C7370616E207374796C653D22464F4E542D46414D494C593A20CBCECCE52C53696D53756E3B20434F4C4F523A20233539353935393B20464F4E542D53495A453A2031347078223EB5E3BBF7D3D2C9CFBDC7A1BED7A2B2E1A1BFA3ACB8F9BEDDCCE1CABECCEED0B4D7A2B2E1D0C5CFA2A1A33C2F7370616E3E3C2F703E3C703E3C7370616E207374796C653D22464F4E542D46414D494C593A20CBCECCE52C53696D53756E3B20434F4C4F523A20233539353935393B20464F4E542D53495A453A2031347078223ED7A2A3BAD3C3BBA7C3FBD0EBCEAACAD6BBFABAC5A1A33C2F7370616E3E3C2F703E3C70207374796C653D22544558542D414C49474E3A2063656E7465722

查看binlog

update CM_NEWS set htmlstatus=1, htmlname=0x3230313430373237323435302E68746D, templateid=25, columnid=7, userid=0x61646D696E, subcolumnid=12, title=0xD7A2B2E1, keyword="", description="", source="", content=0x3C703E3C7370616E207374796C653D22464F4E542D46414D494C593A20CBCECCE52C53696D53756E3B20434F4C4F523A20233539353935393B20464F4E542D53495A453A2031347078223EA2D9203C2F7370616E3E3C7370616E207374796C653D22464F4E542D46414D494C593A20CBCECCE52C53696D53756E3B20434F4C4F523A20233539353935393B20464F4E542D53495A453A2031347078223EB5E3BBF7D3D2C9CFBDC7A1BED7A2B2E1A1BFA3ACB8F9BEDDCCE1CABECCEED0B4D7A2B2E1D0C5CFA2A1A33C2F7370616E3E3C2F703E3C703E3C7370616E207374796C653D22464F4E542D46414D494C593A20CBCECCE52C53696D53756E3B20434F4C4F523A20233539353935393B20464F4E542D53495A453A2031347078223ED7A2A3BAD3C3BBA7C3FBD0EBCEAACAD6BBFABAC5A1A33C2F7370616E3E3C2F703E3C70207374796C653D22544558542D414C49474E3A2063656E746572223E3C7370616E207374796C653D22464F4E542D46414D494C593A20CBCECCE52C53696D53756E3B20434F4C4F523A20233539353935393B20464F4E542D53495A453A2031347078223E3C2F7370616E3E3C2F703E3C70207374796C653D22544558542D414C49474E3A2063656E746572223E3C7370616E207374796C653D22464F4E542D46414D494C593A20CBCECCE52C53696D53756E3B20434F4C4F523A20233539353935393B20464F4E542D53495A453A2031347078223E3C2F7370616E3E3C2F703E3C70207374796C653D22544558542D414C49474E3A2063656E746572223E3C7370616E207374796C653D22464F4E542D46414D494C593A20CBCECCE52C53696D53756E223E3C7370616E207374796C653D22464F4E542D46414D494C593A20CEA2C8EDD1C5BADA2C4D6963726F736F66742059614865693B20434F4C4F523A20233539353935393B20464F4E542D53495A453A2031347078223E3C696D67207374796C653D2257494454483A2036303070783B204845494748543A20333133707822207469746C653D2233332E504E472220626F726465723D223022206873706163653D223022207372633D22687474703A2F2F3230332E3139352E3230322E37353A383038302F636D2F6A732F75656469746F72315F335F352F6A73702F75656469746F72696D67732F32303134303830372F393431313430373337373631353530382E504E47222077696474683D2236303022206865696768743D22333133222F3E3C2F7370616E3E266E6273703B3C2F7370616E3E3C2F703E3C703E3C7370616E207374796C653D22464F4E542D46414D494C593A20CBCECCE52C53696D53756E3B20434F4C4F523A20233539353935393B20464F4E542D53495A453A2031347078223EA2DA20D7A2B2E1CDEAB3C9A3ACC7EBB8F9BEDDCCE1CABEBDF8D0D0D2F8D0D0BFA8C8CFD6A4A1A33C2F7370616E3E3C2F703E, pubdate=2014-08-07 00:00:00, begintime=2014-07-27 00:00:00, endtime=NULL, commend=1 where id=50/*!*/;

主库中16进制文件对应内容

<p><span style="FONT-FAMILY: 宋体,SimSun; COLOR: #595959; FONT-SIZE: 14px"></span><span style="FONT-FAMILY: 宋体,SimSun; COLOR: #595959; FONT-SIZE: 14px">点击右上角【注册】,根据提示填写注册信息。</span></p><p><span style="FONT-FAMILY: 宋体,SimSun; COLOR: #595959; FONT-SIZE: 14px">注:用户名须为手机号。</span></p><p style="TEXT-ALIGN: center"><span style="FONT-FAMILY: 宋体,SimSun; COLOR: #595959; FONT-SIZE: 14px"></span></p><p style="TEXT-ALIGN: center"><span style="FONT-FAMILY: 宋体,SimSun; COLOR: #595959; FONT-SIZE: 14px"></span></p><p style="TEXT-ALIGN: center"><span style="FONT-FAMILY: 宋体,SimSun"><span style="FONT-FAMILY: 微软雅黑,Microsoft YaHei; COLOR: #595959; FONT-SIZE: 14px"><img style="WIDTH: 600px; HEIGHT: 313px" title="33.PNG" border="0" hspace="0" src="http://203.195.202.75:8080/cm/js/ueditor1_3_5/jsp/ueditorimgs/20140807/9411407377615508.PNG" width="600" height="313"/></span>&nbsp;</span></p><p><span style="FONT-FAMILY: 宋体,SimSun; COLOR: #595959; FONT-SIZE: 14px">② 注册完成,请根据提示进行银行卡认证。</span></p>

 

上述两例中binlog中内容均为主库实际内容的utf8编码对应的16进制数。