Select entries from the log only for the given date
--user=USERNAME db-user
--host=HOSTNAME, -h=HOSTNAME
-u=USERNAME
Connect to the MySQL server on the given host
--password=PASSWORD password of db-user
--user=USERNAME, -u=USERNAME
-p=PASSWORD
The MySQL username to use when connecting to the server
--socket=SOCKET mysqld socket file to connect
--password=PASSWORD, -p=PASSWORD
-s=SOCKET
The password to use when connecting to the server
--printerror=1 enable error output
--socket=SOCKET, -s=SOCKET
-e 1
The socket file to use when connecting to the server
--printerror=1, -e 1
Read logfile from STDIN an try to EXPLAIN all SELECT statements. All UPDATE statements are rewritten to an EXPLAIN SELECT statement. The results of the EXPLAIN statement are collected and counted. All results with type=ALL are collected in an separete list. Results are printed to STDOUT.
Enable error output
mysql_explain_log reads its standard input for query log contents. It
uses EXPLAIN to analyze SELECT statements found in the input. UPDATE
statements are rewritten to SELECT statements and also analyzed with
EXPLAIN. mysql_explain_log then displays a summary of its results.
Results are printed to the standard output.
EOF
EOF
}
}
...
@@ -351,46 +364,37 @@ __END__
...
@@ -351,46 +364,37 @@ __END__
mysql_explain_log
mysql_explain_log
Feed a mysqld general logfile (created with mysqld --log) back into mysql
Feed a mysqld general query logfile (created with mysqld --log) back
and collect statistics about index usage with EXPLAIN.
into mysql and collect statistics about index usage with EXPLAIN.
=head1 DISCUSSION
=head1 DISCUSSION
To optimize your indices, you have to know which ones are actually
To optimize your indexes, you must know which ones are actually used
used and what kind of queries are causing table scans. Especially
and what kind of queries are causing table scans. This may not be easy,
if you are generating your queries dynamically and you have a huge
especially if you are generating your queries dynamically and you have
amount of queries going on, this isn't easy.
a huge number of queries being executed.
Use this tool to take a look at the effects of your real life queries.
Use this tool to take a look at the effects of your real life queries.
Then add indices to avoid table scans and remove those which aren't used.
Then add indexes to avoid table scans and remove indexes that aren't used.