데이터 베이스 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 Hentai를 무료로 생성하십시오.

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

공식 Web3 Trading Platform App Rankings의 상위 10 개 (2025 년에 출시) 공식 Web3 Trading Platform App Rankings의 상위 10 개 (2025 년에 출시) Mar 31, 2025 pm 08:09 PM

시장 데이터 및 일반적인 평가 기준을 기반 으로이 기사에는 2025 년에 Top 10 공식 Web3 Trading 플랫폼 앱이 나열되어 있습니다.이 목록은 Binance, OKX, Gate.io, Huobi (현재 HTX), Crypto.com, Coinbase, Kraken, Gemini, Bitmex 및 Bybit과 같은 잘 알려진 플랫폼을 포함합니다. 이러한 플랫폼은 사용자 규모, 거래량, 보안, 규정 준수, 제품 혁신 등의 장점이 있습니다. 예를 들어 Binance는 거대한 사용자 기반 및 풍부한 제품 서비스로 유명하며 Coinbase는 보안 및 규정 준수에 중점을 둡니다. 적절한 플랫폼을 선택하려면 자신의 요구와 위험 허용량에 따라 포괄적 인 고려가 필요합니다.

디지털 통화로 위치를 롤하는 방법? 디지털 통화 롤링 플랫폼은 무엇입니까? 디지털 통화로 위치를 롤하는 방법? 디지털 통화 롤링 플랫폼은 무엇입니까? Mar 31, 2025 pm 07:36 PM

디지털 통화 롤링 포지션은 대출을 사용하여 거래 레버리지를 증폭하여 수익률을 높이는 투자 전략입니다. 이 기사에서는 롤링을 지원하는 거래 플랫폼 (Binance, Okex, Gate.io, Huobi, Bybit 등), 레버리지 계정을 열고, 레버리지를위한 자금을 차입하고, 시장의 실시간 모니터링 및 조정을 피하기 위해 마진을 추가하여 마진을 추가하는 등의 주요 단계를 포함하여 디지털 통화 롤링 프로세스에 대해 자세히 설명합니다. 그러나 롤링 포지션 거래는 매우 위험하며 투자자는주의해서 운영하고 완전한 위험 관리 전략을 공식화해야합니다. 디지털 통화 롤링 팁에 대한 자세한 내용은 계속 읽으십시오.

가상 통화 앱 소프트웨어에 권장되는 웹 사이트는 무엇입니까? 가상 통화 앱 소프트웨어에 권장되는 웹 사이트는 무엇입니까? Mar 31, 2025 pm 09:06 PM

이 기사는 Binance Academy, OKX Learn, Coingecko, Cryptoslate, Coindesk, Investopedia, Coinmarketcap, Huobi University, Coinbase Learn 및 Cryptocompare를 포함하여 잘 알려진 가상 통화 관련 앱 추천 웹 사이트 10 개를 권장합니다. 이 웹 사이트는 가상 통화 시장 데이터, 가격 추세 분석 등과 같은 정보를 제공 할뿐만 아니라 기본 블록 체인 지식, 거래 전략 및 다양한 거래 플랫폼 앱의 튜토리얼 및 리뷰를 포함한 풍부한 학습 리소스를 제공하여 사용자가 더 잘 이해하고 이용할 수 있도록 도와줍니다.

통화 서클에서 일반적으로 사용되는 가상 환전에서 초보자 권장 자습서 통화 서클에서 일반적으로 사용되는 가상 환전에서 초보자 권장 자습서 Mar 31, 2025 pm 10:45 PM

이 기사는 통화 서클의 초보자를위한 자세한 교환 권장 사항 및 입문 자습서를 제공합니다. Coinbase, Binance, Kraken, Ouyi 및 Sesame Open Door와 같은 일반적으로 사용되는 교환을 권장하며 등록, 신원 확인, 보안 설정, 재충전 및 거래 단계가 도입됩니다. 이 기사는 또한 초보자가 디지털 자산 분야에 안전하고 합리적으로 들어가도록 돕기 위해 보안 인식, 위험 관리 및 지속적인 학습의 중요성을 강조합니다.

Web3 Transaction은 어떤 플랫폼에서? Web3 Transaction은 어떤 플랫폼에서? Mar 31, 2025 pm 07:54 PM

이 기사에는 Binance, Okx, Gate.io, Kraken, Bybit, Coinbase, Kucoin, Bitget, Gemini 및 Bitstamp를 포함한 상위 10 개의 잘 알려진 Web3 Trading 플랫폼이 나와 있습니다. 이 기사는 통화 수, 거래 유형 (스팟, 선물, 옵션, NFT 등), 처리 수수료, 보안, 규정 준수, 사용자 그룹 등과 같은 각 플랫폼의 특성을 투자자가 가장 적합한 거래 플랫폼을 선택할 수 있도록 도와줍니다. 고주파 거래자, 계약 거래 애호가 또는 규정 준수 및 보안에 중점을 둔 투자자이든, 참조 정보를 찾을 수 있습니다.

램프 아키텍처에서 Node.js 또는 Python 서비스를 효율적으로 통합하는 방법은 무엇입니까? 램프 아키텍처에서 Node.js 또는 Python 서비스를 효율적으로 통합하는 방법은 무엇입니까? Apr 01, 2025 pm 02:48 PM

많은 웹 사이트 개발자는 램프 아키텍처에서 Node.js 또는 Python 서비스를 통합하는 문제에 직면 해 있습니다. 기존 램프 (Linux Apache MySQL PHP) 아키텍처 웹 사이트 요구 사항 ...

PHP의 CURL 라이브러리를 사용하여 JSON 데이터가 포함 된 게시물 요청을 보내는 방법은 무엇입니까? PHP의 CURL 라이브러리를 사용하여 JSON 데이터가 포함 된 게시물 요청을 보내는 방법은 무엇입니까? Apr 01, 2025 pm 03:12 PM

PHP 개발에서 PHP의 CURL 라이브러리를 사용하여 JSON 데이터를 보내면 종종 외부 API와 상호 작용해야합니다. 일반적인 방법 중 하나는 컬 라이브러리를 사용하여 게시물을 보내는 것입니다 ...

See all articles