In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Editor to share with you how to extract the operation records of the specified table in MySQL binlog. I hope you will get something after reading this article. Let's discuss it together.
A simple Python script that requires an appropriate version of the mysqlbinlog tool installed locally.
Support for Python 2.7 +
Click (here) to collapse or open
# _ * _ coding:utf-8 _ * _
Import sys
Import os
Import io
Binlogfile = sys.argv [1]
Database_name = sys.argv [2]
Table_name = sys.argv [3]
Def format_binlog ():
Os.system ('mysqlbinlog-- base64-output=decode-rows-v' + binlogfile+' >'+ binlogfile+'.txt')
Def pickupbinlog ():
F = io.open (binlogfile+'.txt','r')
Fw = io.open (database_name+'_'+table_name+'.txt','a')
Priv_str =''
Priv_line =''
Goal_flag = 0
For row in f:
# process the first line
If row [0:3] ='# 'and priv_str! =' #':
If database_name in row and table_name in row:
Goal_flag = 1
Fw.write (priv_line)
Fw.write (row)
# handle the last line
If row [0:3]! ='# 'and priv_str =' #':
Goal_flag = 0
# handle target operations
If row [0:3] ='# 'and priv_str = =' # 'and goal_flag = = 1:
Fw.write (row)
Priv_str = row [0:3]
Priv_line = row
F.close ()
Fw.close ()
If _ _ name__ = ='_ _ main__':
# python2.7 pickupbinlog.py mysql-bin.001051 dbname tablename
# python3 pickupbinlog.py mysql-bin.001051 dbname tablename
Format_binlog ()
Pickupbinlog ()
After reading this article, I believe you have a certain understanding of "how to extract the operation records of the specified table in MySQL binlog". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for your reading!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.