mk-merge-mqd-results(1) Merge multiple mk-query-digest reports into one.


mk-query-digest slow.log-1 --save-results res1.txt
mk-query-digest slow.log-2 --save-results res2.txt
mk-merge-mqd-results res1.txt res2.txt


The following section is included to inform users about the potential risks, whether known or unknown, of using this tool. The two main categories of risks are those created by the nature of the tool (e.g. read-only tools vs. read-write tools) and those created by bugs.

At the time of this release, we know of no bugs that could cause serious harm to users.

The authoritative source for updated information is always the online issue tracking system. Issues that affect this tool will be marked as such. You can see a list of such issues at the following URL: <>.

See also ``BUGS'' for more information on filing bugs and getting help.


This is a light-weight script for merging and reporting on results saved by mk-query-digest --save-results.


Prompt for a password when connecting to MySQL.
short form: -A; type: string

Default character set. If the value is utf8, sets Perl's binmode on STDOUT to utf8, passes the mysql_enable_utf8 option to DBD::mysql, and runs SET NAMES UTF8 after connecting to MySQL. Any other value sets binmode on STDOUT without the utf8 layer, and runs SET NAMES after connecting to MySQL.

type: Array

Read this comma-separated list of config files; if specified, this must be the first option on the command line.

short form: -F; type: string

Only read mysql options from the given file. You must give an absolute pathname.

type: array; default: 5,10

Explain items when there are more or fewer than expected.

Defines the number of items expected to be seen in the report as controlled by ``--limit'' and ``--outliers''. If there are more or fewer items in the report, each one will explain why it was included.

type: DSN

Run EXPLAIN for the sample query with this DSN and print results.

This causes mk-merge-mqd-results to run EXPLAIN and include the output into the report. For safety, queries that appear to have a subquery that EXPLAIN will execute won't be EXPLAINed. Those are typically ``derived table'' queries of the form

  select ... from ( select .... ) der;
Add query fingerprints to the standard query analysis report. This is mostly useful for debugging purposes.
default: yes

Print extra information to make analysis easy.

This option adds code snippets to make it easy to run SHOW CREATE TABLE and SHOW TABLE STATUS for the query's tables. It also rewrites non-SELECT queries into a SELECT that might be helpful for determining the non-SELECT statement's index usage.

Show help and exit.
short form: -h; type: string

Connect to host.

type: string; default: 95%:20

Limit output to the given percentage or count.

If the argument is an integer, report only the top N worst queries. If the argument is an integer followed by the "%" sign, report that percentage of the worst queries. If the percentage is followed by a colon and another integer, report the top percentage or the number specified by that integer, whichever comes first.

See also ``--outliers''.

type: string; default: Query_time:sum

Sort events by this attribute and aggregate function.

type: string; default: Query_time:1:10

Report outliers by attribute:percentile:count.

The syntax of this option is a comma-separated list of colon-delimited strings. The first field is the attribute by which an outlier is defined. The second is a number that is compared to the attribute's 95th percentile. The third is optional, and is compared to the attribute's cnt aggregate. Queries that pass this specification are added to the report, regardless of any limits you specified in ``--limit''.

For example, to report queries whose 95th percentile Query_time is at least 60 seconds and which are seen at least 5 times, use the following argument:

  --outliers Query_time:60:5
short form: -p; type: string

Password to use when connecting.

short form: -P; type: int

Port number to use for connection.

type: Array; default: rusage,date,files,header,profile,query_report,prepared

Print these sections of the query analysis report.

  ============ ==============================================================
  rusgae       CPU times and memory usage reported by ps
  date         Current local date and time
  files        Input files read/parse
  header       Summary of the entire analysis run
  profile      Compact table of queries for an at-a-glance view of the report
  query_report Detailed information about each unique query
  prepared     Prepared statements

The sections are printed in the order specified. The rusage, date, files and header sections are grouped together if specified together; other sections are separted by blank lines.

type: string; default: Query_time

Chart the distribution of this attribute's values.

The distribution chart is limited to time-based attributes, so charting "Rows_examined", for example, will produce a useless chart.

type: string; default: wait_timeout=10000

Set these MySQL variables. Immediately after connecting to MySQL, this string will be appended to SET and executed.

type: int; default: 1024

Shorten long statements in reports.

Shortens long statements, replacing the omitted portion with a "/*... omitted ...*/" comment. This applies only to the output in reports, not to information stored other places. It prevents a large statement from causing difficulty in a report. The argument is the preferred length of the shortened statement. Not all statements can be shortened, but very large INSERT and similar statements often can; and so can IN() lists, although only the first such list in the statement will be shortened.

If it shortens something beyond recognition, you can find the original statement in the log, at the offset shown in the report header.

type: Hash

Show all values for these attributes.

By default mk-query-digest only shows as many of an attribute's value that fit on a single line. This option allows you to specify attributes for which all values will be shown (line width is ignored). This only works for attributes with string values like user, host, db, etc. Multiple attributes can be specified, comma-separated.

short form: -S; type: string

Socket file to use for connection.

short form: -u; type: string

User for login if not current user.

Show version and exit.
default: yes

Print 0% boolean values in report.


These DSN options are used to create a DSN. Each option is given like "option=value". The options are case-sensitive, so P and p are not the same option. There cannot be whitespace before or after the "=" and if the value contains whitespace it must be quoted. DSN options are comma-separated. See the maatkit manpage for full details.
  • A

    dsn: charset; copy: yes

    Default character set.

  • D

    dsn: database; copy: yes

    Database that contains the query review table.

  • F

    dsn: mysql_read_default_file; copy: yes

    Only read default options from the given file

  • h

    dsn: host; copy: yes

    Connect to host.

  • p

    dsn: password; copy: yes

    Password to use when connecting.

  • P

    dsn: port; copy: yes

    Port number to use for connection.

  • S

    dsn: mysql_socket; copy: yes

    Socket file to use for connection.

  • t

    Table to use as the query review table.

  • u

    dsn: user; copy: yes

    User for login if not current user.


You can download Maatkit from Google Code at <>, or you can get any of the tools easily with a command like the following:


Where "toolname" can be replaced with the name (or fragment of a name) of any of the Maatkit tools. Once downloaded, they're ready to run; no installation is needed. The first URL gets the latest released version of the tool, and the second gets the latest trunk code from Subversion.


The environment variable "MKDEBUG" enables verbose debugging output in all of the Maatkit tools:

   MKDEBUG=1 mk-....


You need Perl and some core packages that ought to be installed in any reasonably new version of Perl.


For list of known bugs see <>.

Please use Google Code Issues and Groups to report bugs or request support: <>. You can also join #maatkit on Freenode to discuss Maatkit.

Please include the complete command-line used to reproduce the problem you are seeing, the version of all MySQL servers involved, the complete output of the tool when run with ``--version'', and if possible, debugging output produced by running with the "MKDEBUG=1" environment variable.


This program is copyright 2010 Percona Inc. Feedback and improvements are welcome.


This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2; OR the Perl Artistic License. On UNIX and similar systems, you can issue `man perlgpl' or `man perlartistic' to read these licenses.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.


Daniel Nichter


This manual page documents Ver 0.9.19 Distrib 6652 $Revision: 6646 $.