博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
Audit mysql query slow.
1. start slow log.
   Two method:
    (1)edit my.cnf ,add text as belows to [mysqld].
         #if long_query_time=0, all queries will be saved to log file
         long_query_time=1
         #create the log file and give the log file mysql access authority by chown mysql.mysql file_name
         log-slow-queries[=file_name]
    (2)start mysqld with the --log-slow-queries[=file_name]  option.

2.analyze slow log
  I have fond two method to analyze the slow log.
  (1)mysqldumpslow which is supplied by mysql.
    Use this command we can see summarizes of the log file.
    mysqldumpslow file_name  //eg: mysqldumpslow /opt/test/mysql_slow.log
   
  (2)Myprofi.http://myprofi.sourceforge.net/.
    MyProfi is a command line tool that parses mysql query log and outputs statistics of most frequently used queries,
    sorting them by number of times they appear in a log file
    Down the source code from http://myprofi.sourceforge.net/ ,and copy parser.php to centos. Use follow command to analyze the log

   //show all slow queries.
   php parser.php -slow /opt/test/mysql.log

   //show top N slow queries.
   php parser.php -top N -slow /opt/test/mysql.log  
   
   //only show select slow queries, we can also add other options such as update ,insert ,delete.
   php parser.php -top 10 -type "select" -slow /opt/test/mysql.log  
posted on 2010-06-28 10:21  Likwo  阅读(481)  评论(0编辑  收藏  举报