Commit 3a4d188f authored by unknown's avatar unknown

mysql_explain_log.sh:

  Patch from Paul DuBois for better help messages


scripts/mysql_explain_log.sh:
  Patch from Paul DuBois for better help messages
parent be33e018
...@@ -21,9 +21,6 @@ use DBI; ...@@ -21,9 +21,6 @@ use DBI;
use Getopt::Long; use Getopt::Long;
$Getopt::Long::ignorecase=0; $Getopt::Long::ignorecase=0;
print "explain_log provided by http://www.mobile.de\n";
print "=========== ================================\n";
my $Param={}; my $Param={};
$Param->{host}=''; $Param->{host}='';
...@@ -32,16 +29,28 @@ $Param->{password}=''; ...@@ -32,16 +29,28 @@ $Param->{password}='';
$Param->{PrintError}=0; $Param->{PrintError}=0;
$Param->{socket}=''; $Param->{socket}='';
if (!GetOptions ('date|d:i' => \$Param->{ViewDate}, my $help;
if (!GetOptions (
'date|d:i' => \$Param->{ViewDate},
'host|h:s' => \$Param->{host}, 'host|h:s' => \$Param->{host},
'user|u:s' => \$Param->{user}, 'user|u:s' => \$Param->{user},
'password|p:s' => \$Param->{password}, 'password|p:s' => \$Param->{password},
'printerror|e:s' => \$Param->{PrintError}, 'printerror|e:s' => \$Param->{PrintError},
'socket|s:s' => \$Param->{socket}, 'socket|s:s' => \$Param->{socket},
'help|h' => \$help,
)) { )) {
ShowOptions(); ShowOptions();
exit(0);
} }
else { if (defined ($help)) {
ShowOptions();
exit(0);
}
print "explain_log provided by http://www.mobile.de\n";
print "=========== ================================\n";
$Param->{UpdateCount} = 0; $Param->{UpdateCount} = 0;
$Param->{SelectCount} = 0; $Param->{SelectCount} = 0;
$Param->{IdxUseCount} = 0; $Param->{IdxUseCount} = 0;
...@@ -245,7 +254,6 @@ else { ...@@ -245,7 +254,6 @@ else {
print "Finished: \t".localtime(time)."\n"; print "Finished: \t".localtime(time)."\n";
} }
}
########################################################################### ###########################################################################
...@@ -323,21 +331,26 @@ sub ShowOptions { ...@@ -323,21 +331,26 @@ sub ShowOptions {
print <<EOF; print <<EOF;
Usage: $0 [OPTIONS] < LOGFILE Usage: $0 [OPTIONS] < LOGFILE
--date=YYMMDD select only entrys of date --help, -h
-d=YYMMDD Display this help message
--host=HOSTNAME db-host to ask --date=YYMMDD, -d=YYMMDD
-h=HOSTNAME 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.
=head1 USAGE =head1 USAGE
mysql_explain_log [--date=YYMMDD] --host=dbhost] [--user=dbuser] [--password=dbpw] [--socket=/path/to/socket] < logfile mysql_explain_log [--date=YYMMDD] --host=dbhost] [--user=dbuser] [--password=dbpw] [--socket=/path/to/socket] [--printerror=1] < logfile
--date=YYMMDD select only entrys of date --help, -h
Display this help message
-d=YYMMDD --date=YYMMDD, -d=YYMMDD
Select entries from the log only for the given date
--host=HOSTNAME db-host to ask --host=HOSTNAME, -h=HOSTNAME
Connect to the MySQL server on the given host
-h=HOSTNAME --user=USERNAME, -u=USERNAME
The MySQL username to use when connecting to the server
--user=USERNAME db-user --password=PASSWORD, -p=PASSWORD
The password to use when connecting to the server
-u=USERNAME --socket=SOCKET, -s=SOCKET
The socket file to use when connecting to the server
--password=PASSWORD password of db-user --printerror=1, -e 1
Enable error output
-p=PASSWORD
--socket=SOCKET change path to the socket
-s=SOCKET
--printerror=1 enable error output
-e 1
=head1 EXAMPLE =head1 EXAMPLE
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment