python 处理 mysql 慢查日志

2018-08-01

112

0

技术:python2.7

运行环境:python2.7 + windows 10

demo功能:提供一个python 处理mysql 慢查日志的代码dmeo

源代码

# coding:utf8
import os
import sys
import time

LOG_FILE = 'slow_query_3306.log'


def main():
    counter = 0
    res = []
    with open(LOG_FILE, 'r') as lines:
        for line in lines:
            if counter > 0:
                counter += 1
            if line.find('# Time: ') >= 0:
                counter = 1

            if counter == 1:
                res.append(line.split()[2]);
            if counter == 2:
                res.append(line.split()[2]);
            if counter == 3:
                res.append(line.split()[2]);
    print len(res)


if __name__ == '__main__':
    main()

结果 (时间-操作用户-耗时seconds)

 
 

欢迎添加微信,互相学习↑↑↑ -_-

发表评论

全部评论:0条

白老虎

programming is not only to solve problems, ways to think