ホームページ データベース mysql チュートリアル mysql慢查询日志分析工具使用_MySQL

mysql慢查询日志分析工具使用_MySQL

May 27, 2016 pm 01:46 PM
道具 ログ

1.mysql-log-filter工具脚本使用说明:

google code上找到的一个分析工具.提供了 python 和 php 两种可执行的脚本。http://code.google.com/p/mysql-log-filter/ (需要搬梯子爬墙),51cto下载链接:http://down.bitsCN.com/data/2123725

使用方法:(这里只介绍python的使用方法)

python mysql_filter_slow_log.py  ./mysql1-slow.log --no-duplicates --sort-execution-count --top=10  >> mysql_slow_test.txt

备注:mysql1-slow.log  慢查询日志名称

 --no-duplicates

 --sort-execution-count

 --top=10  取前十位

 mysql_slow_test.txt  输出分析报告

 

附录:

 

官方给出的使用方法举例:

=====================================

 

# 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 test
tail -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 filtering
kill `ps auxww | grep 'tail -f -n 0 linux-slow.log' | egrep -v grep | awk '{print $2}'`
ログイン後にコピー

====================================

官方给出的命令参数:

==================================

-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. &#39;--date=>13.11.2006&#39;).
                            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 statistics
Default 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.
ログイン後にコピー

====================================

官方给出的配置文件中管理慢日志参数的配置

====================================

# 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 seconds
long_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 Log
slow_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 information
log-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 &#39;admin|min_examined|log_output|log_queries|log_slave|long|slow_quer&#39;
ログイン後にコピー

 

======================================

 

注意:在执行脚本的时候会报数据类型的错误,具体错误指定469行,经过查看,实际慢查询日志中的query_time是float类型,而在这个脚本工具中定义的确实int类型。于是自行修改!

 

默认:

======================

 

query_time = (int(numbers[1].split()[0]), int(numbers[2].split()[0]),

              int(numbers[3].split()[0]), int(numbers[4]))

======================

 

修改为:

======================

 

query_time = (float(numbers[1].split()[0]), float(numbers[2].split()[0]),

              float(numbers[3].split()[0]), float(numbers[4]))

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

GOのどのライブラリが大企業によって開発されていますか、それとも有名なオープンソースプロジェクトによって提供されていますか? GOのどのライブラリが大企業によって開発されていますか、それとも有名なオープンソースプロジェクトによって提供されていますか? Apr 02, 2025 pm 04:12 PM

大企業または有名なオープンソースプロジェクトによって開発されたGOのどのライブラリが開発されていますか? GOでプログラミングするとき、開発者はしばしばいくつかの一般的なニーズに遭遇します...

Giteeページ静的なWebサイトの展開に失敗しました:単一のファイル404エラーをトラブルシューティングと解決する方法 Giteeページ静的なWebサイトの展開に失敗しました:単一のファイル404エラーをトラブルシューティングと解決する方法 Apr 04, 2025 pm 11:54 PM

GiteEpages静的Webサイトの展開が失敗しました:404エラーのトラブルシューティングと解像度Giteeを使用する

Avue-Crudの行編集モードでセルのOnblurイベントを手動でトリガーする方法は? Avue-Crudの行編集モードでセルのOnblurイベントを手動でトリガーする方法は? Apr 04, 2025 pm 02:00 PM

AvueコンポーネントライブラリでAvue-Crudの行編集を実装するOnblurイベントは、Avue-Crudコンポーネントを手動でトリガーします。便利なインライン編集機能を提供しますが、時にはする必要があります...

AIツールを使用して、React Viteプロジェクトでフォアグラウンドページをすばやく構築するにはどうすればよいですか? AIツールを使用して、React Viteプロジェクトでフォアグラウンドページをすばやく構築するにはどうすればよいですか? Apr 04, 2025 pm 01:45 PM

バックエンド開発でフロントエンドページをすばやく構築する方法は? 3年または4年の経験を持つバックエンド開発者として、彼は基本的なJavaScript、CSS、HTMLを習得しました...

ブラウザ埋め込みスクリプトを使用して、Webページ要素の操作と数値計算を自動化する方法は? ブラウザ埋め込みスクリプトを使用して、Webページ要素の操作と数値計算を自動化する方法は? Apr 04, 2025 pm 12:09 PM

Webページの自動化と数値計算:ブラウザー埋め込みスクリプトに基づく実装この記事では、ブラウザ組み込みスクリプトを使用してWebページ要素の操作と数字を実装する方法を探ります。

NPMの代わりにPNPMでReactアプリケーションを作成する方法は? NPMの代わりにPNPMでReactアプリケーションを作成する方法は? Apr 04, 2025 pm 06:45 PM

NPMの代わりにPNPMを使用して、NPXを使用してReactアプリケーションを作成することについて...

Chrome DevtoolsでリクエストされたCookieを効果的に変更および再生する方法は? Chrome DevtoolsでリクエストされたCookieを効果的に変更および再生する方法は? Apr 04, 2025 pm 05:48 PM

Chromeを使用してChromedevtoolsでリクエストされたCookieを効果的に変更および再生する方法...

グラデーションの背景を持つカードとクーポンのレイアウトに対するギャップ効果を達成する方法は? グラデーションの背景を持つカードとクーポンのレイアウトに対するギャップ効果を達成する方法は? Apr 05, 2025 am 07:48 AM

カードクーポンレイアウトのギャップ効果を実現します。カードクーポンレイアウトを設計するとき、特に背景が勾配である場合、カードクーポンにギャップを追加する必要があることがよくあります...

See all articles