Home Database Mysql Tutorial python写的分析mysql binlog日志工具

python写的分析mysql binlog日志工具

Jun 07, 2016 pm 05:38 PM
binlog python analyze tool log

因为数据库增删改突然暴增,需要查询是那些表的操作特别频繁,写了一个用来分析bin-log的小工具,找出增删改查的表,并按照操作次数降序排列,以下是代码:#form

因为数据库增删改突然暴增,需要查询是那些表的操作特别频繁,写了一个用来分析bin-log的小工具,,找出增删改查的表,并按照操作次数降序排列,以下是代码:

#for mysql5.5 binlog import os,sys #python binlog.py binglog-0001 '2013-07-01 00:00:00' '2013-07-02 00:00:00' def log_w(type,text): logfile = "%s.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 a): update = ' '.join(a.split()[:2]) mylist.append(update) if ('INSERT INTO' in a): update = ' '.join(a.split()[:3]).replace("INTO ","") mylist.append(update) if ('DELETE from' in a): 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]

spacer.gif

spacer.gif

执行结果如下:

165939295.jpg


本文出自 “王伟” 博客,请务必保留此出处

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the recommended websites for virtual currency app software? What are the recommended websites for virtual currency app software? Mar 31, 2025 pm 09:06 PM

This article recommends ten well-known virtual currency-related APP recommendation websites, including Binance Academy, OKX Learn, CoinGecko, CryptoSlate, CoinDesk, Investopedia, CoinMarketCap, Huobi University, Coinbase Learn and CryptoCompare. These websites not only provide information such as virtual currency market data, price trend analysis, etc., but also provide rich learning resources, including basic blockchain knowledge, trading strategies, and tutorials and reviews of various trading platform APPs, helping users better understand and make use of them

Recommended tutorial for newbies in the commonly used virtual currency exchange in the currency circle Recommended tutorial for newbies in the commonly used virtual currency exchange in the currency circle Mar 31, 2025 pm 10:45 PM

This article provides detailed exchange recommendations and introductory tutorials for beginners in the currency circle. Commonly used exchanges such as Coinbase, Binance, Kraken, Ouyi and Sesame Open Door are recommended, and the steps for registration, identity verification, security settings, recharge and trading are introduced. The article also emphasizes the importance of security awareness, risk control and continuous learning, aiming to help beginners enter the digital asset field safely and rationally.

What are the free market software websites What are the free market software websites Mar 31, 2025 pm 10:36 PM

There are six free market viewing software websites: 1. Binance platform, suitable for digital asset investors; 2. OKX platform, providing rich market data; 3. Sesame Open Door (Gate.io) platform, suitable for users who trade in Gate.io; 4. TradingView, providing professional charting tools; 5. CoinMarketCap, covering a wide range of digital asset data; 6. CoinGecko, providing project fundamental evaluation. When choosing a platform, you need to consider investment objects, chart function requirements, data comprehensiveness and user experience.

The latest tutorial for commonly used virtual currency exchanges in the currency circle 2025 The latest tutorial for commonly used virtual currency exchanges in the currency circle 2025 Mar 31, 2025 pm 10:57 PM

This article recommends several commonly used and relatively safe virtual currency exchanges for beginners entering the currency circle in 2025, including Binance, Ouyi, Coinbase and Sesame Open Door. The article provides detailed tutorials on registration, authentication, security setup and transaction process, and emphasizes the importance of risk control, security awareness and ongoing learning, aiming to help beginners securely get started with digital asset trading.

The latest recommendations for commonly used virtual currency exchanges in the currency circle 2025 The latest recommendations for commonly used virtual currency exchanges in the currency circle 2025 Mar 31, 2025 pm 10:54 PM

This article recommends several virtual currency exchanges commonly used in the cryptocurrency circle in 2025, including Binance, Ouyi, Coinbase, Sesame Open Door and Kraken, and emphasizes the security, liquidity, trading fees and other factors that need to be considered when choosing an exchange. At the same time, it provides beginners with suggestions, reminding them to carefully read user agreements, enable two-factor verification, start trying with small funds, etc., and emphasize cautious investment and risk control.

How to efficiently parse multi-layer nested brackets in LaTeX formulas and convert them into multi-dimensional dictionary? How to efficiently parse multi-layer nested brackets in LaTeX formulas and convert them into multi-dimensional dictionary? Apr 01, 2025 am 08:57 AM

Python parses LaTeX multi-layer brackets: build multi-dimensional dictionary many LaTeX...

QueryList proxy settings are invalid and crawler recognition: How to effectively bypass the website anti-crawler mechanism? QueryList proxy settings are invalid and crawler recognition: How to effectively bypass the website anti-crawler mechanism? Mar 31, 2025 pm 11:21 PM

Analysis of QueryList proxy settings failure and crawler identification problems Many users will encounter even if the proxy is set up when crawling websites such as 58.com using the QueryList library...

See all articles