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. TNS-12560,TNS-00583: Valid node checking: unable to parse configuration parameters

    测试环境11.2.0.4.0, os系统linux 5.6 单实例,监听文件,启动报错: [oracle@adg1 admin]$ lsnrctl start LSNRCTL for Linux: V ...

  2. 计算机基础-C语言-16章-数组应用-计算字符串长度

    字符数组的大小并不代表它所包含字符串的长度.需要通过检查结束符,才能判断字符串的实际长度. 数组和指针的关系

  3. UML作业第三次:分析《书店图书销售管理系统》

    分析图书销售管理系统 一.概览 PlantUML类图语法学习小结 <书店图书销售管理>的类图元素 绘制类图脚本程序 绘制的类图 二.PlantUML类图语法 1.类之间的关系绘制 示例: ...

  4. ccf-炉石传说-201609-3

    大概是CCF 第三题比较简洁的一道题吧 尽量设计好一个数据结构: node t[2][10]: 存双方的英雄和随从 int    num[2]: 存隋朝的数量 用p来实现双方的切换,因为有统一 的接口 ...

  5. angular6 引用echart第一次数据不显示解决

    1 使用promise从后台返回数据后,页面还是比数据更快的加载出来,导致echart图页面加载的时候不显示问题 1.1 html <div echarts [options]="do ...

  6. maven 使用axis2 client 需要导入的依赖

    <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2</artif ...

  7. QT5.10+VS2013 TCP 一对一简单C/S架构通信

    ---恢复内容开始--- QT~俺老孙又回来啦~ 买的那本书上面关于tcp的内容就七八页,而且都是过于简单的东西,想进一步就要度娘很久很麻烦,还是喜欢看书(嘿嘿嘿~) 大致的思路就是两个项目,一个cl ...

  8. 《python for data analysis》第四章,numpy的基本使用

    <利用python进行数据分析>第四章的程序,介绍了numpy的基本使用方法.(第三章为Ipython的基本使用) 科学计算.常用函数.数组处理.线性代数运算.随机模块…… # -*- c ...

  9. android BluetoothAdapter蓝牙BLE扫描总结

    1.android 4.3.1(Build.VERSION_CODES.JELLY_BEAN_MR2)增加的startLeScan(callback)方法,官方在5.0之后不建议使用,实测此方法,4. ...

  10. LG3211 [HNOI2011]XOR和路径

    题意 题目描述 给定一个无向连通图,其节点编号为 1 到 N,其边的权值为非负整数.试求出一条从 1 号节点到 N 号节点的路径,使得该路径上经过的边的权值的"XOR 和"最大.该 ...