Often need to find some log information in the Binlog, so wrote a simple script. For a very large Binlog file, the script may be slow, after all, still use the list, temporarily did not think of a good way.
See the code in detail:
#/usr/bin/python#2016-04-12#search String in the Binlogs#Usage:#put this file into binlog-dir,exec as:#"Python test.py 111 123 Update" or#"Python test.py 111 123 update and insert" or#"Python test.py 111 123 update or delete"#The nums is the binlog-num.ImportSYSImportsubprocessdeffind_str (Files): forFileinchFiles:comm="mysqlbinlog {0}". Format (file) lines= subprocess. Popen (comm, Shell=true, stdout=subprocess. PIPE) Lines=Lines.stdout.readlines () forLineinchLines:line=Line.lower ()ifLen (sys.argv) = = 4: ifSYS.ARGV[3] +"' inchLine :yield LineelifLen (sys.argv) = = 6 andSYS.ARGV[4] = =" and": ifSYS.ARGV[3] +"' andSYS.ARGV[5] +"' inchLine :yield LineelifLen (sys.argv) = = 6 andSYS.ARGV[4] = ="or": ifSYS.ARGV[3] +"' orSYS.ARGV[5] +"' inchLine :yield Lineif __name__=="__main__": Start= Sys.argv[1] End= Sys.argv[2] Files= ["Updatelog. {0:06d}". Format (i) forIinchRange (int (start), int (end) +1)] F=find_str (Files) forIinchF:Print(i)
Python Find Binlog File