Because the addition, deletion, and modification of the MySQL database suddenly increase, the operations on the tables that need to be queried are very frequent. I wrote a small tool to analyze the bin-log and find the tables for addition, deletion, modification, and query, and sorted in descending order according to the number of operations, the following is the code:
# For mysql5.5 binlog
Import OS, sys
# Python binlog. py binglog-0001 '2017-07-01 00:00:00 ''2017-07-02 00:00:00'
Def log_w (type, text ):
Logfile = "cmds.txt" % (type, text)
# Now = time. strftime ("% Y-% m-% d % H: % M: % S ")
Tt = str (text) + "\ n"
F = open (logfile, 'a + ')
F. write (tt)
F. close ()
Logname = sys. argv [1]
Start_time = sys. argv [2]
End_time = sys. argv [3]
Comn = "/usr/bin/mysqlbinlog -- start-datetime = '% s' -- stop-datetime =' % s' % s" % (start_time, end_time, logname)
Aa = OS. popen (comn). readlines ()
Mylist = []
For a in aa:
If ('update' in ):
Update = ''. join (a. split () [: 2])
Mylist. append (update)
If ('insert into' in ):
Update = ''. join (a. split () [: 3]). replace (" ","")
Mylist. append (update)
If ('delete from' in ):
Update = ''. join (a. split () [: 3]). replace (" from ","")
Mylist. append (update)
Mylist. sort ()
Bb = list (set (mylist ))
Bb. sort ()
Cc = []
For item in bb:
Cc. append ([mylist. count (item), (item)])
Cc. sort ()
Cc. reverse ()
For I in cc:
Print str (I [0]) + '\ t' + I [1]
The execution result is as follows:
How to safely delete binlog logs under MySQL
MySQL -- binlog log data recovery
How does MySQL Delete binlog and restore Data?
Introduction and Analysis of Three MySQL binlog formats
MySQL uses binlog Incremental backup + restore instance
MySQL deletes binlog logs and restores data.
Implementation and performance of MySQL binlog pre-allocation