mysql自带的工具真多啊,可见强大,原来学习过一个mysql自己备份的工具,应该是mysqldump,配合linun认为,每天备份数据库,还原也方便,今天推荐一个查看慢日志的工具 mysqldumpslow,执行mysqldumpslow --help 可以查看其相关参数和说明:
[root@mysql ~]# mysqldumpslow --help 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 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
-s:是表示按照何种方式排序;
c: 访问计数;
l: 锁定时间;
r: 返回记录;
t: 查询时间;
al:平均锁定时间;
ar:平均返回记录数;
at:平均查询时间;
-t:是top n的意思,即为返回前面多少条的数据;
-g:后边可以写一个正则匹配模式,大小写不敏感的。
mysqldumpslow -s r -t 10 /mysql/mysql_slow.log mysqldumpslow -s c -t 10 /mysql/mysql_slow.log