0. precondition

a) install mysql 5.7, for  detail please refer my blog post.

1. login mysql and check the variables to see if the binlog has  been enabled.

mysql -h 127.0.0.1 -uroot -proot
show variables like '%log_bin%';

we can see, the log_bin is disabled.

2. Turn on mysql log_bin

sudo vim /etc/mysql/conf.d/mysql.cnf 

add the following config segment at the end of the file

# ----------------------------------------------
# Enable the binlog for replication & CDC
# ---------------------------------------------- # Enable binary replication log and set the prefix, expiration, and log format.
# The prefix is arbitrary, expiration can be short for integration tests but would
# be longer on a production system. Row-level info is required for ingest to work.
# Server ID is required, but this will vary on production systems
server-id =
log_bin = /var/lib/mysql/mysql-bin
expire_logs_days =
binlog_format = row
#Mysql Packet Size may need to be re-configured. MySQL may have, by default, a ridiculously low allowable packet size.
#To increase it, you’ll need to have the property max_allowed_packet set to a higher number, say 1024M.
max_allowed_packet=1024M

this configration means:

a) the server id is unique for each server, an is required for log_bin capture, it should be a numeric number equal or greater than 0, in my instance I set it to 223344, this number should be unique in the whole cluster.  seems it's a good idea to set it as the ip

address number of the machine install. I fact I have do this in my real production enviroment.

b) the path of the log_bin, this is required  to define the storage location fo the log_bin.

c) the log_bin retention time, in my case, I set it to 3 days.

d. the bin_log format, we should define it as row.

The whole definition file in my case is:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at % of total RAM for dedicated server, else %.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
skip-host-cache
skip-name-resolve
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
#secure-file-priv=/var/lib/mysql-files
user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links= #log-error=/var/log/mysqld.log
#pid-file=/var/run/mysqld/mysqld.pid # ----------------------------------------------
# Enable the binlog for replication & CDC
# ---------------------------------------------- # Enable binary replication log and set the prefix, expiration, and log format.
# The prefix is arbitrary, expiration can be short for integration tests but would
# be longer on a production system. Row-level info is required for ingest to work.
# Server ID is required, but this will vary on production systems
server-id =
log_bin = /var/lib/mysql/mysql-bin
expire_logs_days =
binlog_format = row
#Mysql Packet Size may need to be re-configured. MySQL may have, by default, a ridiculously low allowable packet size.
#To increase it, you’ll need to have the property max_allowed_packet set to a higher number, say 1024M.
max_allowed_packet=1024M
#set default charactor set to utf-
character-set-server=utf8
collation-server=utf8_unicode_ci

3. restart mysql service

systemctl restart mysql

after the mysql restarted, we use the command

show variables like '%log_bin%';

and we should found the log_bin is turned on now:  log_bin                         | ON  

then we go to file system, and can fould like this :

the log bin files are just there now!

-rw-r----- 1 mysql mysql 177 Apr 20 15:06 mysql-bin.000001
-rw-r----- 1 mysql mysql 154 Apr 20 15:22 mysql-bin.000002
-rw-r----- 1 mysql mysql 64 Apr 20 15:22 mysql-bin.index

In order to read mysql binlog, we need to grant the mysql user the following permissions:

  • SELECT

  • RELOAD

  • SHOW DATABASES

  • REPLICATION SLAVE

  • REPLICATION CLIENT

The first three privileges are required when reading a consistent snapshot of the databases. The last two privileges allow the database to read the server’s binlog that is normally used for MySQL replication.

you can see the permmission for the user by execute the following command in mysql terminal.

show grants for cdc-user ;  -- cdc-user is the user name I used to do cdc synchronization.

the output is

--------------------------+
| Grants for cdc-user@% |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT RELOAD, PROCESS, ALTER, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'cdc-user'@'%' IDENTIFIED BY PASSWORD '*C8C6BD45F62159406C6E0587C42BDE28FFA5F973' |
| GRANT SELECT, LOCK TABLES, SHOW VIEW ON `inventory`.* TO 'cdc-user'@'%' |
| GRANT SELECT ON `mysql`.`help_relation` TO 'cdc-user'@'%' |
| GRANT SELECT ON `mysql`.`time_zone_leap_second` TO 'cdc-user'@'%' |
| GRANT SELECT ON `mysql`.`time_zone_name` TO 'cdc-user'@'%' |
| GRANT SELECT ON `mysql`.`proc` TO 'cdc-user'@'%' |
| GRANT SELECT ON `mysql`.`general_log` TO 'cdc-user'@'%' |
| GRANT SELECT ON `mysql`.`slow_log` TO 'cdc-user'@'%' |
| GRANT SELECT ON `mysql`.`func` TO 'cdc-user'@'%' |
| GRANT SELECT ON `mysql`.`help_topic` TO 'cdc-user'@'%' |
| GRANT SELECT ON `mysql`.`time_zone_transition_type` TO 'cdc-user'@'%' |
| GRANT SELECT ON `mysql`.`event` TO 'cdc-user'@'%' |
| GRANT SELECT ON `mysql`.`time_zone_transition` TO 'cdc-user'@'%' |
| GRANT SELECT ON `mysql`.`time_zone` TO 'cdc-user'@'%' |
| GRANT SELECT ON `mysql`.`help_keyword` TO 'cdc-user'@'%' |
| GRANT SELECT ON `mysql`.`help_category` TO 'cdc-user'@'%' |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+

this indicate the user also need select permission for mysql database.

Notes: every time we restart the mysql server instance, it will  call flush logs and then create a new binlog file. 

mysql 5.7 enable binlog的更多相关文章

  1. MySQL Q&A 解析binlog的两个问题

    MySQL Q&A 解析binlog的两个问题 博客分类: MySQL mysqlbinlog字符集解析binlog格式 连续碰到两个同学问类似的问题,必须要记录一下. 问题:     一个作 ...

  2. mysql之 innobackupex备份+binlog日志的完全恢复【转】

    前言: MySQL的完全恢复,我们可以借助于完整的 备份+binlog 来将数据库恢复到故障点. 备份可以是热备与逻辑备份(mysqldump),只要备份与binlog是完整的,都可以实现完全恢复. ...

  3. MySQL 之 mysqlbinlog解析binlog乱码问题解密

    发现mysql库的binlog日志出来都是乱码,如下所示: BINLOG ’ IXZqVhNIAAAALQAAAGcBAAAAAHoAAAAAAAEABHRlc3QAAno0AAEDAABUOcnY ...

  4. mysql中删除binlog的方法?mysql中如何删除binlog?

    需求描述: 在mysql中如何删除binlog,因为随着数据库的运行,mysql中产生的binlog会越来越大,有可能把磁盘撑爆了,所以记录下删除 binlog的方法. 操作过程: 1.通过系统参数控 ...

  5. MySQL redo log 与 binlog 的区别

    MySQL redo log 与 binlog 的区别 什么是redo log 什么是binlog redo log与binlog的区别 1. 什么是redo log? redo log又称重做日志文 ...

  6. MySQL 5.7 - 通过 BINLOG 恢复数据

    日常开发,运维中,经常会出现误删数据的情况.误删数据的类型大致可分为以下几类: 使用 delete 误删行 使用 drop table 或 truncate table 误删表 使用 drop dat ...

  7. mysql小白系列_04 binlog(未完)

    mysql打开.查看.清理binlog 1.开启日志 log_bin=/var/lib/mysql/mysql-bin mysql> show variables like '%log_bin% ...

  8. Mysql 数据恢复流程 基于binlog redolog undolog

    注:文中有个易混淆的地方 sql事务,即每次数据库操作生成的事务,这个事务trx_id只在undolog里存储,同时undolog维护了此事务是否完成的状态. 日志持久化事务,为了保证redolog和 ...

  9. mysql的DISABLE/ENABLE KEYS

    有一个表 tbl1 的结构如下: CREATE TABLE `tbl1` ( `id` int(10) unsigned NOT NULL auto_increment, `name` char(20 ...

随机推荐

  1. 云原生GIS技术

    云原生架构概述 - DockOne.io  http://dockone.io/article/2991 云原生GIS技术全解读 - SuperMap技术控 - CSDN博客  https://blo ...

  2. Spark SQL / Catalyst 内部原理 与 RBO

    原创文章,转载请务必将下面这段话置于文章开头处. 本文转发自技术世界,原文链接 http://www.jasongj.com/spark/rbo/ 本文所述内容均基于 2018年9月10日 Spark ...

  3. nodejs-QQ空间灌水

    在本地编写javascript代码,node环境下命令行内运行,请求网页实现给QQ好友留言. 1.登录QQ空间,给好友留言,在开发者工具中打开网络面板,在network中找到addXXX开头的请求. ...

  4. windows 安装touch指令

    if you are using node.js just use npm to install it on Windows: C:\npm install touch-cli -g

  5. 【[AHOI2005]洗牌 题解

    一道好题. 首先是数据范围. 0<N≤10^10 ,0 ≤M≤10^10,且N为偶数 这是这道题的坑点,也是痛点. 10^10表示这这道题必有规律. 那么,first step,我们先探索规律. ...

  6. 491. Increasing Subsequences

    这种increasing xxx 题真是老客户了.. 本题麻烦点在于不能重复, 但是和之前的那些 x sum的题目区别在于不能排序的 所以.... 我还是没搞定. 看了一个Java的思路是直接用set ...

  7. 学习笔记CB003:分块、标记、关系抽取、文法特征结构

    分块,根据句子的词和词性,按照规则组织合分块,分块代表实体.常见实体,组织.人员.地点.日期.时间.名词短语分块(NP-chunking),通过词性标记.规则识别,通过机器学习方法识别.介词短语(PP ...

  8. 5. Web vulnerability scanners (网页漏洞扫描器 20个)

    5. Web vulnerability scanners (网页漏洞扫描器 20个) Burp Suite是攻击Web应用程序的集成平台. 它包含各种工具,它们之间有许多接口,旨在方便和加快攻击应用 ...

  9. 如何写更少的 if else

    首先声明,不是要消除if 而是,减少一些不必要的if判断,使得代码更优雅,更重要的是提高可维护性 most easy use Ternary: var result = condiction? tru ...

  10. Boot Hill 布特山

    发售年份 1977 平台 街机 开发商 Midway 类型 射击 https://www.youtube.com/watch?v=yFVZhSCjo6w