mysql 5.7 enable binlog
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的更多相关文章
- MySQL Q&A 解析binlog的两个问题
MySQL Q&A 解析binlog的两个问题 博客分类: MySQL mysqlbinlog字符集解析binlog格式 连续碰到两个同学问类似的问题,必须要记录一下. 问题: 一个作 ...
- mysql之 innobackupex备份+binlog日志的完全恢复【转】
前言: MySQL的完全恢复,我们可以借助于完整的 备份+binlog 来将数据库恢复到故障点. 备份可以是热备与逻辑备份(mysqldump),只要备份与binlog是完整的,都可以实现完全恢复. ...
- MySQL 之 mysqlbinlog解析binlog乱码问题解密
发现mysql库的binlog日志出来都是乱码,如下所示: BINLOG ’ IXZqVhNIAAAALQAAAGcBAAAAAHoAAAAAAAEABHRlc3QAAno0AAEDAABUOcnY ...
- mysql中删除binlog的方法?mysql中如何删除binlog?
需求描述: 在mysql中如何删除binlog,因为随着数据库的运行,mysql中产生的binlog会越来越大,有可能把磁盘撑爆了,所以记录下删除 binlog的方法. 操作过程: 1.通过系统参数控 ...
- MySQL redo log 与 binlog 的区别
MySQL redo log 与 binlog 的区别 什么是redo log 什么是binlog redo log与binlog的区别 1. 什么是redo log? redo log又称重做日志文 ...
- MySQL 5.7 - 通过 BINLOG 恢复数据
日常开发,运维中,经常会出现误删数据的情况.误删数据的类型大致可分为以下几类: 使用 delete 误删行 使用 drop table 或 truncate table 误删表 使用 drop dat ...
- mysql小白系列_04 binlog(未完)
mysql打开.查看.清理binlog 1.开启日志 log_bin=/var/lib/mysql/mysql-bin mysql> show variables like '%log_bin% ...
- Mysql 数据恢复流程 基于binlog redolog undolog
注:文中有个易混淆的地方 sql事务,即每次数据库操作生成的事务,这个事务trx_id只在undolog里存储,同时undolog维护了此事务是否完成的状态. 日志持久化事务,为了保证redolog和 ...
- mysql的DISABLE/ENABLE KEYS
有一个表 tbl1 的结构如下: CREATE TABLE `tbl1` ( `id` int(10) unsigned NOT NULL auto_increment, `name` char(20 ...
随机推荐
- InstallShield 软件打包完整教程(含添加自定义依赖环境)
任务说明:公司一个绿色版的软件,为安装部署是需要很多的环境依赖,如 DevExpress..net4.5.WinRAR等,客户提出安装复杂,并且有漏装后无法启动等情况,现将绿色版转安装版,并将依赖环境 ...
- docker-compose部署mongodb+redis遇到的问题
Demo环境下需要用到Redis+mongodb两种DB配合使用,所以暂时直接使用docker的redids和mongodb镜像,用docker-compose进行联合部署 使用的版本如下: dock ...
- Dart 创建Map
Map的常用操作 1. [] , length 获取值和长度 2. isEmpty (),isNoEmpty () 是否为空 3.Keys ,values 获取所有的键 和值 4. contai ...
- MySQL 8.0常见问题
1.连接问题: 1.1:8.0的驱动地址更换由原来的com.mysql.jdbc.Driver改为com.mysql.cj.jdbc.Driver 1.2:8.0以后访问地址要加上时区.编码等属性jd ...
- Leetcode 两数之和 (散列表)
给定一个整数数组和一个目标值,找出数组中和为目标值的两个数. 你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用. 示例: 给定 nums = [2, 7, 11, 15], target ...
- DbVisualizer中SQL编辑框输入中文显示乱码
打开tools工具栏,选择tool properties,选择General--Appearance--Fonts,将fonts上面的三个字体都设置为仿宋,Apply,OK.
- ue4 StringTable
StringTable 用法很简单可以参考 https://blog.csdn.net/u012801153/article/details/80393531 这里只说说上面文章中没提到的小技巧 T ...
- vue项目打包后的资源路径问题
最近做的vue项目,本地测试完成后,build上线,却发现了文件路径问题,提示各种诸如js,css等资源找不到的错: 正确解决方式有两种,一种是绝对路径配置,详细可以网上查,个人推荐第二种相对路径,这 ...
- req和resp常用的方法
req: 1. setAttribute()在Request域中存储数据 2. setCharacterEncoding()设置请求参数的编码方式,只对post请求有效 3. getMethod() ...
- python selenium-webdriver 元素操作之键盘操作(五)
上节介绍了模拟鼠标对元素的操作,本节主要介绍键盘对元素的操作,实际过程中鼠标对元素的操作比键盘对元素的操作更经常使用,但是键盘对元素的操作也很重要,本节主要介绍一下键盘对元素的操作. selenium ...