mysql性能优化——mysqldumpslow

 

使用mysqldumpslow分析慢sql日志。

首选要打开slowsql。那么有哪些参数可以设置呢?   

mysql性能优化——mysqldumpslow_第1张图片

可以设置慢查询开头,慢查询sql日志文件的位置

mysql性能优化——mysqldumpslow_第2张图片

可以设置慢查询耗时时长

可以直接在mysql启动状态下修改(重启无效):

mysql> set global slow_query_log = on;
mysql> set slow_query_log_file=/var/lib/mysql/host-slow.log;
mysql> set long_query_time=100;

或者打开my.cnf(重启有效)

[mysqld] 
datadir=/var/lib/mysql 
socket=/var/lib/mysql/mysql.sock 
skip-grant-tables
slow_query_log=on
long_query_time=100
slow_query_log_file=/var/lib/mysql/host-slow.log
log_queries_not_using_indexes=on

 

然后mysql运行一段时间后,会有慢sql日志:

Usage: mysqldumpslow [ OPTS... ] [ LOGS... ]

Parse and summarize the MySQL slow query log. Options are

  --verbose    verbose
  --debug      debug
  --help       write this text to standard output

  -v           verbose
  -d           debug
  -s ORDER     what to sort by (al, at, ar, c, l, r, t), 'at' is default
                al: average lock time(按平均锁定时间排序)
                ar: average rows sent(按平均行数排序)
                at: average query time(按平均查询时间排序)
                 c: count(sql次数)
                 l: lock time(锁定时间)
                 r: rows sent(行数)
                 t: query time (查询时间) 
  -r           reverse the sort order (largest last instead of first)(倒序)
  -t NUM       just show the top n queries
  -a           don't abstract all numbers to N and strings to 'S'
  -n NUM       abstract numbers with at least n digits within names
  -g PATTERN   grep: only consider stmts that include this string
  -h HOSTNAME  hostname of db server for *-slow.log filename (can be wildcard),
               default is '*', i.e. match all
  -i NAME      name of server instance (if using mysql.server startup script)
  -l           don't subtract lock time from total time

如:按sql次数查询

mysql性能优化——mysqldumpslow_第3张图片

你可能感兴趣的:(性能优化)