Wednesday, January 21, 2015

Steps to check MySQL Slow queries with Percona Tool(Pt-Query-digit)


1.Download latest Percona tool kit.

Download from here ,

http://www.percona.com/downloads/percona-toolkit/LATEST/

2.Percona tool kit Installation steps here,

http://knowmysql.blogspot.in/2013/09/percona-tool-kit-installation.html

3.After installation enable Slow query log variable in MySQL

a.Enable through my.cnf for permanent

add below two lines,

    slow_query_log=ON
    long_query_time=5

Restart mysql

b.Enable for the current session

login to mysql server

    >set global slow_query_log=ON;
    > set global long_query_time=5;

4.By default slow query log file will be in MySQL data directory

go to mysql data directory and see hostname-slow.log

wait for few hours to get the slow queries in the log file.

5.Now run the pt-query-digit to see the slow queries

#pt-query-digest /mysqldatadirectorypath/hostname-slow.log > /backup/slowqueries.txt

6.Now evaluate the slow queries.

#less /backup/slowqueries.txt

here first in overall session you can see the total details

Second you can see the list of top queries in rankwise.

Third full details of each queries.

in the each queries the main things to see is,

Total number of execute time of the query from by 95% column.