mysql慢查询日志分析工具(python写的)
D:\NormalSoftware>python mysql_filter_slow_log.py ./mysql1-slow.log --no-duplic
ates --sort-avg-query-time --top=100 >> mysql_slow_test05.txt
469行要改为:
query_time = (float(numbers[1].split()[0]), float(numbers[2].split()[0]),
float(numbers[3].split()[0]), float(numbers[4]))
150 151行注释掉:
#locale.setlocale(locale.LC_NUMERIC,
# os.name == 'nt' and 'en' or 'en_US.ISO8859-1')
mysql_filter_slow_log.py
使用方法:(这里只介绍python的使用方法)
|
1
2
3
4
5
6
7
8
9
|
# Filter slow queries executed for at least 3 seconds not from root, remove duplicates,# apply execution count as first sorting value and save first 10 unique queries to file.# In addition, remember last input file position and statistics.php mysql_filter_slow_log.php -T=3 -eu=root --no-duplicates --sort-execution-count --top=10 --incremental linux-slow.log > mysql-slow-queries.log# Start permanent filtering of all slow queries from now on: at least 3 seconds or examining 10000 rows, exclude users root and testtail -f -n 0 linux-slow.log | python mysql_filter_slow_log.py -T=3 -R=10000 -eu=root -eu=test &# (-n 0 outputs only lines generated after start of tail)# Stop permanent filteringkill `ps auxww | grep 'tail -f -n 0 linux-slow.log' | egrep -v grep | awk '{print $2}'` |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
-T=min_query_time-R=min_rows_examined-ih, --include-host-eh, --exclude-host-iu, --include-user-eu, --exclude-user-iq, --include-query--date=date_first-date_last Include only queries between date_first (and date_last). Input: Date Range: 13.11.2006 -> 13.11.2006 - 14.11.2006 (exclusive) 13.11.2006-15.11.2006 -> 13.11.2006 - 16.11.2006 (exclusive) 15-11-2006-11/13/2006 -> 13.11.2006 - 16.11.2006 (exclusive) >13.11.2006 -> 14.11.2006 - later 13.11.2006- -> 13.11.2006 - later <13.11.2006 -> earlier - 13.11.2006 (exclusive) -13.11.2006 -> earlier - 14.11.2006 (exclusive) Please do not forget to escape the greater or lesser than symbols (><, i.e. '--date=>13.11.2006'). Short dates are supported if you include a trailing separator (i.e. 13.11.-11/15/).--incremental Remember input file positions and optionally --no-duplicates statistics between executions in mysql_filter_slow_log.sqlite3--no-duplicates Powerful option to output only unique query strings with additional statistics: Execution count, first and last timestamp. Query time: avg / max / sum. Lock time: avg / max / sum. Rows examined: avg / max / sum. Rows sent: avg / max / sum.--no-output Do not print statistics, just update database with incremental statisticsDefault ordering of unique queries:--sort-sum-query-time [ 1. position]--sort-avg-query-time [ 2. position]--sort-max-query-time [ 3. position]--sort-sum-lock-time [ 4. position]--sort-avg-lock-time [ 5. position]--sort-max-lock-time [ 6. position]--sort-sum-rows-examined [ 7. position]--sort-avg-rows-examined [ 8. position]--sort-max-rows-examined [ 9. position]--sort-execution-count [10. position]--sort-sum-rows-sent [11. position]--sort-avg-rows-sent [12. position]--sort-max-rows-sent [13. position]--sort=sum-query-time,avg-query-time,max-query-time,... You can include multiple sorting values separated by commas.--sort=sqt,aqt,mqt,slt,alt,mlt,sre,are,mre,ec,srs,ars,mrs Every long sorting option has an equivalent short form (first character of each word).--top=max_unique_query_count Output maximal max_unique_query_count different unique queries--details Enables output of timestamp based unique query time lines after user list (i.e. # Query_time: 81 Lock_time: 0 Rows_sent: 884 Rows_examined: 2448350).--help Output this message only and quit[multiple] options can be passed more than once to set multiple values.[position] options take the position of their first occurrence into account. The first passed option will replace the default first sorting, ... Remaining default ordering options will keep their relative positions. |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# I.e. you could add the following lines under the [mysqld] section of your my.ini or my.cnf configuration file:# Log all queries taking more than 3 secondslong_query_time=3 # minimum: 1, default: 10# MySQL >= 5.1.21 (or patched): 3 seconds = 3000000 microseconds# long_query_time=3.000000 # minimum: 0.000001 (1 microsecond)# Activate the Slow Query Logslow_query_log # >= 5.1.29# log-slow-queries # deprecated since 5.1.29# Write to a custom file name (>= 5.1.29)# slow_query_log_file=file_name # default: /data_dir/host_name-slow.log# Log all queries without indexes# log-queries-not-using-indexes# Log only queries which examine at least N rows (>= 5.1.21)# min_examined_row_limit=1000 # default: 0# Log slow OPTIMIZE TABLE, ANALYZE TABLE, and ALTER TABLE statements# log-slow-admin-statements# Log slow queries executed by replication slaves (>= 5.1.21)# log-slow-slave-statements# MySQL 5.1.6 through 5.1.20 had a default value of log-output=TABLE, so you should force# Attention: logging to TABLE only includes whole seconds informationlog-output=FILE## Admin query for online activation is possible since MySQL 5.1 (without server restart)## SET @@global.slow_query_log=1## SET @@global.long_query_time=1## Show current variables related to the Slow Query Log## SHOW GLOBAL VARIABLES WHERE Variable_name REGEXP 'admin|min_examined|log_output|log_queries|log_slave|long|slow_quer' |
mysql慢查询日志分析工具(python写的)的更多相关文章
- mysql慢查询日志分析工具 mysqlsla(转)
mysql数据库的慢查询日志是非常重要的一项调优辅助日志,但是mysql默认记录的日志格式阅读时不够友好,这是由mysql日志记录规则所决定的,捕获一条就记录一条,虽说记录的信息足够详尽,但如果将浏览 ...
- mysql慢查询日志分析工具mysqldumpslow
一.mysqldumpslow为mysql自带,安装后既带有该工具. 二.mysqldumpslow经常使用的参数 -s,是order的顺序 al 平均锁定时间 ar 平均返回记录时间 at 平均查询 ...
- MySQL 慢查询日志分析工具(pt-query-digest)
1. 慢查询命令: 是否开启和日志路径:show variables like '%slow_query_log%'; 最大查询时间:show variables like '%query_time% ...
- 慢查询日志分析工具之pt-query-digest
简介 pt-query-digest 是用于分析mysql慢查询的一个工具,与mysqldumpshow工具相比,py-query_digest 工具的分析结果更具体,更完善. 有时因为 ...
- Mysql慢查询(分析工具)
慢查询分析工具[mysqldumpslow] 常用的慢查询日志分析工具 汇总除查询条件外其他完全相同的SQL,并将分析结果按照参数中所指定的顺序输出 语法: mysqldumpslow -s r -t ...
- MySQL 慢查询日志分析及可视化结果
MySQL 慢查询日志分析及可视化结果 MySQL 慢查询日志分析 pt-query-digest分析慢查询日志 pt-query-digest --report slow.log 报告最近半个小时的 ...
- pt-query-digest查询日志分析工具
1.工具介绍 pt-query-digest是用于分析mysql慢查询的一个工具,它可以分析binlog.General log.slowlog,也可以通过SHOWPROCESSLIST或者通过tcp ...
- MySQL慢查询日志分析
一:查询slow log的状态,如示例代码所示,则slow log已经开启. mysql> show variables like '%slow%'; +-------------------- ...
- MySQL慢查询日志分析提取【转】
原文:https://www.cnblogs.com/skymyyang/p/7239010.html 一:查询slow log的状态,如示例代码所示,则slow log已经开启. mysql> ...
随机推荐
- Navicat 破解版的安装
因为电脑系统换掉,重装系统,重新配置了一下环境,安装Navicat,现记录一下过程,以便下次查询使用. 我们首先百度搜索一款navicat for mysql然后进行下载. 2 当我们下载完成之后首先 ...
- samba 服务实现在windows共享文件
1. 什么是samba Samba服务类似于windows上的共享功能,可以实现在Linux上共享文件,windows上访问,当然在Linux上也可以访问到. 是一种在局域网上共享文件和打印机的一种通 ...
- session的作用范围(转)
session是在服务器端建立的,浏览器访问服务器会有一个jsessionid,浏览器端通过 jsessionid定位服务器端的session,session的创建和销毁由服务器端控制.当浏览器关闭后 ...
- 【OpenGL4.0】GLSL渲染语言入门与VBO、VAO使用:绘制一个三角形 【转】
http://blog.csdn.net/xiajun07061225/article/details/7628146 以前都是用Cg的,现在改用GLSL,又要重新学,不过两种语言很多都是相通的. 下 ...
- ElasticSearch 相关性
1.相关性 ElasticSearch检索结果是按照相关性倒序排列的,相关性是什么,相关性又是如何计算的?每个文档都有相关性评分,用一个正浮点数字段 _score 来表示 . _score 的评分越高 ...
- Linux alias理解及设置
1.alias简介 Linux alias 是命令的一种别称,输入 alias 可以看到像下面这样的结果: alias l.='ls -d .* --color=auto' alias ll='ls ...
- CKEditor+SWFUpload实现功能较为强大的编辑器(一)---CKEditor配置
CKEditor爆表的强大功能大家都有目共睹,号称最强大的在线编辑器,只要将文件复制到项目中,在添加引用,在一句代码就可以将普通的textarea变成华丽的编辑器 所谓一复制,一拖,一换就大功告成 但 ...
- 初识Nginx及编译安装Nginx
初识Nginx及编译安装Nginx 环境说明: 系统版本 CentOS 6.9 x86_64 软件版本 nginx-1.12.2 1.什么是Nginx? 如果你听说或使用过Apache软件 ...
- hibernate学习系列-----(2)hibernate核心接口和工作机制
在上一篇文章hibernate学习系列-----(1)开发环境搭建中,大致总结了hibernate的开发环境的搭建步骤,今天,我们继续了解有关hibernate的知识,先说说这篇文章的主要内容吧: C ...
- 倍福TwinCAT(贝福Beckhoff)基础教程 松下伺服驱动器报错 81.0怎么办
同步周期有问题 请确认MOTION的伺服周期是一致的,最好跟MAIN主程序也一样,所有周期都是2ms即可 更多教学视频和资料下载,欢迎关注以下信息: 我的优酷空间: http://i.yo ...