通过mysqldumpslow来分析日志

Posted 认真生活、快乐工作 - 马云

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过mysqldumpslow来分析日志相关的知识,希望对你有一定的参考价值。

通过mysqldumpslow来分析日志。

将mysql加入到全局变量中!!!

sudo vim /etc/profile
# 添加Mysql
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile

前提是这个日志文件需要设置可访问权限。

最好还是弄一个软连接到/usr/bin下面。

sudo ln -s /usr/local/mysql/bin/mysqldumpslow /usr/bin/mysqldumpslow

列出了最慢的三条日志信息。

sudo mysqldumpslow -t 3 /tmp/mysql-slow.log 

Reading mysql slow query log from /tmp/mysql-slow.log
Count: 1  Time=0.33s (0s)  Lock=0.00s (0s)  Rows=23.0 (23), root[root]@localhost
  SELECT *,
  `TABLE_SCHEMA`       AS `Db`,
  `TABLE_NAME`         AS `Name`,
  `TABLE_TYPE`         AS `TABLE_TYPE`,
  `ENGINE`             AS `Engine`,
  `ENGINE`             AS `Type`,
  `VERSION`            AS `Version`,
  `ROW_FORMAT`         AS `Row_format`,
  `TABLE_ROWS`         AS `Rows`,
  `AVG_ROW_LENGTH`     AS `Avg_row_length`,
  `DATA_LENGTH`        AS `Data_length`,
  `MAX_DATA_LENGTH`    AS `Max_data_length`,
  `INDEX_LENGTH`       AS `Index_length`,
  `DATA_FREE`          AS `Data_free`,
  `AUTO_INCREMENT`     AS `Auto_increment`,
  `CREATE_TIME`        AS `Create_time`,
  `UPDATE_TIME`        AS `Update_time`,
  `CHECK_TIME`         AS `Check_time`,
  `TABLE_COLLATION`    AS `Collation`,
  `CHECKSUM`           AS `Checksum`,
  `CREATE_OPTIONS`     AS `Create_options`,
  `TABLE_COMMENT`      AS `Comment`
  FROM `information_schema`.`TABLES` t
  WHERE `TABLE_SCHEMA` COLLATE utf8_bin
  IN ('S')
  ORDER BY Name ASC LIMIT N OFFSET N

Count: 1  Time=0.05s (0s)  Lock=0.00s (0s)  Rows=1.0 (1), root[root]@localhost
  SELECT COUNT(*) FROM `sakila`.`film_actor`

Count: 1  Time=0.04s (0s)  Lock=0.00s (0s)  Rows=1.0 (1), root[root]@localhost
  SELECT COUNT(*) FROM `sakila`.`rental`

以上是关于通过mysqldumpslow来分析日志的主要内容,如果未能解决你的问题,请参考以下文章

《MySQL系列-InnoDB引擎15》慢查询日志拓展-mysqldumpslow日志分析工具

mysqldumpslow -- 分析慢查询日志

mysqldumpslow 分析slow query日志和explain分析mysql查询结构

mysql 开启慢查询及其用mysqldumpslow做日志分析

mysql 开启慢查询及其用mysqldumpslow做日志分析

Mysql优化_慢查询开启说明及Mysql慢查询分析工具mysqldumpslow用法讲解