Home  >  Article  >  Database  >  mysql-MySQL二进制日志使用遇到的编码问题

mysql-MySQL二进制日志使用遇到的编码问题

WBOY
WBOYOriginal
2016-06-06 09:42:52952browse

日志mysql

以下是MySQL的二进制日志数据,其中
问题1:日志中/*!\C binary //!*/; 和 /*!\C utf8 //!*/;是什么作用?

使用场景:
解析二进制日志,存储到数据库中
再调取出来执行到别一个数据库

问题2:
存储SQL的时候会出现乱码,如
alter table lezhi_app.tmp
change etid etid int(11) NOT NULL comment '编号'
其中“编号”就成乱码了,SQl调取出来执行的时候就会报错,无法执行?(数据库默认使用了set names gbk,不使用set names的话也是乱码)

解决方案:
解析 /*!\C utf8 //!*/ 中的utf8,加上set names utf8 后,可以正常存储执行

问题2:
很多SQL是在 /*!\C binary //!*/; 下面
执行 set names binary 后,有部分中文SQL存储出现乱码(存储出现 ???)。
(我们数据编码用的是GBK)

<code> COMMIT/*!*/;# at 87931309#150108 20:08:13 server id 5  end_log_pos 87931465     Query    thread_id=2649685    exec_time=0    error_code=0use `lezhi_app`/*!*/;SET TIMESTAMP=1420718893/*!*/;<span style="color: #FF0000;">/*!\C utf8 *//*!*/;</span>SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=8/*!*/;alter table `lezhi_app`.`tmp`    change `etid` `etid` int(11) NOT NULL comment '编号'/*!*/;# at 87931465#150108 20:08:13 server id 5  end_log_pos 87931529     Query    thread_id=2649874    exec_time=0    error_code=0SET TIMESTAMP=1420718893/*!*/;<span style="color: #FF0000;">/*!\C binary *//*!*/;</span>SET @@session.character_set_client=63,@@session.collation_connection=28,@@session.collation_server=8/*!*/;BEGIN/*!*/;# at 87931529</code>

数据库编码是这样的:

图片说明

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn