In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly shows you the "sample analysis based on the mysql replication tool in python", which is easy to understand and well-organized. I hope it can help you solve your doubts. Let the editor lead you to study and study the "sample analysis based on the mysql replication tool in python".
A brief introduction
Python-mysql-replication is a MySQL replication protocol tool based on python. We can use it to parse events such as insert,update,delete when binlog gets logs, and do other business requirements based on it. For example, if the cache is invalidated when the data is changed, the listening dml event will notify the downstream business party to deal with it accordingly.
Its project information
II practice 2.1 installation configuration
Get the source code
Git clone http://www.github.com/noplay/python-mysql-replication
Install using pip
Pip install mysql-replication
Permissions: you can use either a copy account or another account directly, but the account must have SELECT, REPLICATION SLAVE and REPLICATION CLIENT permissions
GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON. TO 'replicator'@'%' IDENTIFIED BY' xxxxx'
The parameters related to the database log are set as follows:
Log_bin=on, introduction to binlog_format=row,binlog_row_image=FULL2.2 core classes
The entry to python-mysql-replication is class BinLogStreamReader (). When we use this tool, we need to instantiate a BinLogStreamReader () object stream. BinLogStreamReader is registered as a slave role with the main library through ReportSlave to receive binlog broadcasts from MySQL. Those who are interested can study the specific implementation of the code.
This instance provides a collection of events that parse the binlog, each of which is also an object.
The parameters needed to initialize the BinLogStreamReader () instance are as follows:
2.3 how to use it?
The simplest use is the script name pyreplica.py
Open two windows, one window executes, and the other window operates mysql to write or modify data
Python pyreplica.py
The output is as follows:
2.3 expansion
Based on the log event parsing provided by this tool, we can do a lot of things. The more famous tool binlog2sql uses this tool to parse binlog to do data rollback.
Mysql-replication.py
The result of executing the script is as follows
In addition to parsing binlog, we can also use python-mysql-replication for full plus incremental data migration. For example, it can be used when only some large tables are migrated instead of the entire library.
The above is all the content of this article "sample Analysis based on mysql replication tool in python". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.