mysql 5.7 binlog_mysql 5.7 enable binlog-程序员宅基地

技术标签: mysql 5.7 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%';

7ced89e03051f7440cf00f7d18349864.png

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 binlogfor replication &CDC

#----------------------------------------------# Enable binary replication log and set the prefix, expiration, and log format.

# The prefix is arbitrary, expiration can beshort forintegration tests but would

# be longer on a production system. Row-level info is required foringest to work.

# Server ID is required, but this will vary on production systems

server-id = 223344log_bin= /var/lib/mysql/mysql-bin

expire_logs_days= 3binlog_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:

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

# 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 RAMforthe most important data

# cachein MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# 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 usefulforreporting servers.

# The server defaults are fasterfortransactions and fast SELECTs.

# Adjust sizes as needed, experiment tofindthe 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=0#log-error=/var/log/mysqld.log

#pid-file=/var/run/mysqld/mysqld.pid

#----------------------------------------------# Enable the binlogfor replication &CDC

#----------------------------------------------# Enable binary replication log and set the prefix, expiration, and log format.

# The prefix is arbitrary, expiration can beshort forintegration tests but would

# be longer on a production system. Row-level info is required foringest to work.

# Server ID is required, but this will vary on production systems

server-id = 223344log_bin= /var/lib/mysql/mysql-bin

expire_logs_days= 3binlog_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-8character-set-server=utf8

collation-server=utf8_unicode_ci

View Code

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

2f966b5660911695842ae93f7e823fe0.png

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

fa7f4516ac274e2b18da6831bd23561b.png

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.

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_35744893/article/details/113187894

智能推荐

BCrypt密码加密的简单使用_bcrypt加密-程序员宅基地

文章浏览阅读5.7k次。一.BCrypt基础在一个项目中,只要涉及用户的登陆注册,就涉及到用户密码的保护,用户的密码存在数据库是对管理员是透明的,所以为了防止管理员泄露密码,提高用户密码的安全性,我们通常会对用户密码进行加密后再存入数据库,目前MD5与Bcrypt使用比较多,都不可反向破解生成明文。但任何长度的密码使用MD5加密后长度都是相同的,固定的。而且一个密码使用MD5加密生成的密文唯一。那我就可以记下所有明文使用MD5加密后的密文,解密使用穷举就可以破解。MD5解密网站:https://www.bejson.com/en_bcrypt加密

互联网的载体--操作系统_互联网载体-程序员宅基地

文章浏览阅读5k次。第一章 操作系统引论系统的目标:有效性(提高资源利用率和系统吞吐量)、方便性、可扩充性、开放性。有效性和方便性是操作系统最重要两个目标。操作系统的作用:(1) OS作为用户与计算机硬件系统之间的接口(2) OS作为计算机系统资源的管理者(处理器、存储器、I/O设备、数据程序)(3) OS实现了对计算机资源的抽象(在硬件上覆盖I/O设备、文件_互联网载体

px to rem & rpx & vw cssrem 设置_pxtovw,不想要vw-程序员宅基地

文章浏览阅读657次,点赞11次,收藏8次。第一步第二步第三步。_pxtovw,不想要vw

json文件-程序员宅基地

文章浏览阅读7.7k次,点赞3次,收藏35次。一般都使用类似字典的方式存储,但和字典不同,无论是键还是值,都要加上双引号。直接使用记事本打开:例如猫狗二分类。_json文件

wsl安装库的时候出现/usr/lib/wsl/lib/libcuda.so.1 is not a symbolic link-程序员宅基地

文章浏览阅读1.7k次,点赞3次,收藏6次。当在安装库的时候出现这个语句,是ld的链接出现了问题,我们只需要创建一个新的文件路径,在/usr/lib/wsl目录下创建一个文件夹,我使用的文件名字是lib2,大家只需要创建一个你们可以记得住的名字就行。将文件中的/usr/lib/wsl/lib修改为/usr/lib/wsl/lib2即可。输入sudo ldconfig看是否生效,没有报错就是成功了。_/usr/lib/wsl/lib/libcuda.so.1 is not a symbolic link

node.js/Vue-钓鱼分享平台设计与实现--80679(免费领源码+开发文档)可做计算机毕业设计JAVA、PHP、爬虫、APP、小程序、C#、C++、python、数据可视化、大数据、全套文案-程序员宅基地

文章浏览阅读1.8k次,点赞45次,收藏44次。本系统采取MySQL作为后台数据的主要存储单元,采用Node.ja语言、JSP技术、Ajax技术进行业务系统的编码及其开发,设计了一个专门针对钓鱼爱好用户的钓鱼分享平台。

随便推点

LWIP应用开发|LWIP移植和裁剪_lwip flash裁剪-程序员宅基地

文章浏览阅读1.2k次。LWIP移植和裁剪_lwip flash裁剪

CnOpenData商务服务业基本信息表-程序员宅基地

文章浏览阅读964次,点赞21次,收藏19次。截至2021.12.31。

通过Mixamo生成人物动画并导入Unity实现资源可用的方法_mixamo导出的模型没有材质球-程序员宅基地

文章浏览阅读1.2w次,点赞24次,收藏89次。通过Mixamo生成人物动画并导入Unity实现资源可用的方法:文章要点:如何通过Mixamo生成人物动画在Mixamo中生成的模型及动画导入Unity的设置(保持原有材质)在Unity中利用上述导入素材制作Animator如果你有自己的人物模型,想将自己的人物添加动画并运用到Unity项目中去;或者你没有自己的人物模型,但又想制作Unity人物动画,本篇记录将为你提供一种方式——自己的人物模型通过Mixamo(网址:https://www.mixamo.com/#/ )生成动画的方法(教_mixamo导出的模型没有材质球

Python 学习——Python requests 库文档_python requests 文档-程序员宅基地

文章浏览阅读1k次,点赞19次,收藏27次。如果你改变了编码,每当你访问 r.text ,Request 都将会使用 r.encoding 的新值。如果你创建了自己的编码,并使用 codecs 模块进行注册,你就可以轻松地使用这个解码器名称作为 r.encoding 的值, 然后由 Requests 来为你处理编码。接收者可以合并多个相同名称的 header 栏位,把它们合为一个 “field-name: field-value” 配对,将每个后续的栏位值依次追加到合并的栏位值中,用逗号隔开即可,这样做不会改变信息的语义。_python requests 文档

计算机基础知识掌握评语,计算机学生老师评语-程序员宅基地

文章浏览阅读529次。计算机老师如何写评语主要是思维能力和操作能力两个方面当然如果有游戏的话,还要看是否守纪小学计算机老师如何写评语由于学生对计算机的学习普遍形式化,有些学生实际上也未学到什么知识,但一般学生,对开,关机以及简单的文字输入还是会的,所以,在写评语时,既不能过于夸大孩子的计算机能力,让家长误解为孩子懂电脑了,也不能说学生什么没有学到,这样家长也会认为孩子在学校学电脑只是一个样子,会与老师不负责相联系,那就..._知识点没掌握好怎么写评语

LLM 大模型框架 LangChain 可观测性最佳实践_did not find openai_api_key, please add an environ-程序员宅基地

文章浏览阅读1.1k次,点赞23次,收藏19次。LLM(Large Language Model)大模型的可观测性是指对模型内部运行过程的理解和监控能力。由于LLM大模型通常具有庞大的参数量和复杂的网络结构,因此对其内部状态和运行过程的理解和监控是一个重要的问题。_did not find openai_api_key, please add an environment variable `openai_api_

推荐文章

热门文章

相关标签