想要获取每天数据库每张表的DML的次数,统计热度表,可以使用该脚本
# coding:utf-8
# 解析binlog,统计热度表,表的DML个数
import sys
import os
# mysqlbinlog解析binlog日志
def binlog_output():
binlog_file = sys.argv[1]
file_num = binlog_file.split('.')[1]
binlog_log = 'binlog_%s.log' % file_num
os.system('/usr/local/mysql5637/mysql/bin/mysqlbinlog -v --base64-output=decode-rows %s > %s' %(binlog_file, binlog_log))
return binlog_log
# 对
def binlog_parse(binlog_log):
delete_count = 0
update_count = 0
insert_count = 0
update_li = []
insert_li = []
delete_li = []
stop_time_li = []
binlog_f = open(binlog_log, 'r',encoding='utf-8')
for line in binlog_f.readlines():
if line.startswith(&