How to analyze queries from query execution logs in MySQL

8:53 PM

Below are few options to analyze queries from query execution logs in MySQL:
1) We can use mysqlbinlog utility giving the mysql bin-log file as the argument and the options --start-datetime and --end-datetime and list out all the statements (SQL) that was logged during a particular time period of interest. But with these we can only get DML(insert,update & delete queries). But we will not get select queries.
2) We can use general logging. AS of MySQl 5.1 configuration variable is dynamic and so we can dynamically set and unset whenever we want. i.e we can set it for the scheduled time of debug window including considerable time before & after the problem query runs. For MySQl 5.0 there is a round-about way to enabling general-logging without restarting server. To do this:
a) set global general-log =1;
b) set global general_log_file="/var/lib/mysql/mysql-gen.log"
At the OS the file may be a symbolic link to /dev/null. If not set symbolic link to /dev/null so that it is not writing to any file and is growing big.
/var/lib/mysql/mysql-gen.log -->/dev/null
c) To enable general logging without restarting server we need to run
At the OS: rm /var/lib/mysql/mysql-gen.log
At the MySQL prompt: > flush logs;
3) We can use pt-query-digest available at http://www.percona.com/doc/percona-toolkit/pt-query-digest.html. This tool can parse any query execution logs like MySQL general-log, slow-query-log and bin-log.

You Might Also Like

0 comments

Contact Form

Name

Email *

Message *

Translate

Wikipedia

Search results