From dee239f243795d78250609219bd8d654795ed9f7 Mon Sep 17 00:00:00 2001 From: Joe Horn Date: Thu, 6 Nov 2014 19:43:43 +0800 Subject: [PATCH 1/5] Update mysqltuner.pl * information_schema.ENGINES doesn't exist before MySQL 5.1 * table cache var. depends on MySQL version --- mysqltuner.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mysqltuner.pl b/mysqltuner.pl index 77bf83f..20e39c8 100755 --- a/mysqltuner.pl +++ b/mysqltuner.pl @@ -532,7 +532,7 @@ sub check_storage_engines { print "\n-------- Storage Engine Statistics -------------------------------------------\n"; infoprint "Status: "; my $engines; - if (mysql_version_ge(5)) { + if (mysql_version_ge(5, 1)) { my @engineresults = `mysql $mysqllogin -Bse "SELECT ENGINE,SUPPORT FROM information_schema.ENGINES WHERE ENGINE NOT IN ('performance_schema','MyISAM','MERGE','MEMORY') ORDER BY ENGINE ASC"`; foreach my $line (@engineresults) { my ($engine,$engineenabled); @@ -947,7 +947,7 @@ sub mysql_stats { } else { $table_cache_var = "table_cache"; } - push(@adjvars,$table_cache_var." (> ".$myvar{'table_open_cache'}.")"); + push(@adjvars,$table_cache_var." (> ".$myvar{$table_cache_var}.")"); push(@generalrec,"Increase ".$table_cache_var." gradually to avoid file descriptor limits"); push(@generalrec,"Read this before increasing ".$table_cache_var." over 64: http://bit.ly/1mi7c4C"); } else { From 604900d5367b54a757784582944e7f54424a0454 Mon Sep 17 00:00:00 2001 From: Erik Ljungstrom Date: Tue, 2 Dec 2014 12:58:57 +0000 Subject: [PATCH 2/5] Fixed reporting for temporary tables created on disk. Created_tmp_disk_tables is a subset of Created_tmp_tables --- mysqltuner.pl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mysqltuner.pl b/mysqltuner.pl index 20e39c8..939dce7 100755 --- a/mysqltuner.pl +++ b/mysqltuner.pl @@ -701,7 +701,7 @@ sub calculations { # Temporary tables if ($mystat{'Created_tmp_tables'} > 0) { if ($mystat{'Created_tmp_disk_tables'} > 0) { - $mycalc{'pct_temp_disk'} = int(($mystat{'Created_tmp_disk_tables'} / ($mystat{'Created_tmp_tables'} + $mystat{'Created_tmp_disk_tables'})) * 100); + $mycalc{'pct_temp_disk'} = int(($mystat{'Created_tmp_disk_tables'} / $mystat{'Created_tmp_tables'}) * 100); } else { $mycalc{'pct_temp_disk'} = 0; } @@ -906,17 +906,17 @@ sub mysql_stats { # Temporary tables if ($mystat{'Created_tmp_tables'} > 0) { if ($mycalc{'pct_temp_disk'} > 25 && $mycalc{'max_tmp_table_size'} < 256*1024*1024) { - badprint "Temporary tables created on disk: $mycalc{'pct_temp_disk'}% (".hr_num($mystat{'Created_tmp_disk_tables'})." on disk / ".hr_num($mystat{'Created_tmp_disk_tables'} + $mystat{'Created_tmp_tables'})." total)\n"; + badprint "Temporary tables created on disk: $mycalc{'pct_temp_disk'}% (".hr_num($mystat{'Created_tmp_disk_tables'})." on disk / ".hr_num($mystat{'Created_tmp_tables'})." total)\n"; push(@adjvars,"tmp_table_size (> ".hr_bytes_rnd($myvar{'tmp_table_size'}).")"); push(@adjvars,"max_heap_table_size (> ".hr_bytes_rnd($myvar{'max_heap_table_size'}).")"); push(@generalrec,"When making adjustments, make tmp_table_size/max_heap_table_size equal"); push(@generalrec,"Reduce your SELECT DISTINCT queries without LIMIT clauses"); } elsif ($mycalc{'pct_temp_disk'} > 25 && $mycalc{'max_tmp_table_size'} >= 256) { - badprint "Temporary tables created on disk: $mycalc{'pct_temp_disk'}% (".hr_num($mystat{'Created_tmp_disk_tables'})." on disk / ".hr_num($mystat{'Created_tmp_disk_tables'} + $mystat{'Created_tmp_tables'})." total)\n"; + badprint "Temporary tables created on disk: $mycalc{'pct_temp_disk'}% (".hr_num($mystat{'Created_tmp_disk_tables'})." on disk / ".hr_num($mystat{'Created_tmp_tables'})." total)\n"; push(@generalrec,"Temporary table size is already large - reduce result set size"); push(@generalrec,"Reduce your SELECT DISTINCT queries without LIMIT clauses"); } else { - goodprint "Temporary tables created on disk: $mycalc{'pct_temp_disk'}% (".hr_num($mystat{'Created_tmp_disk_tables'})." on disk / ".hr_num($mystat{'Created_tmp_disk_tables'} + $mystat{'Created_tmp_tables'})." total)\n"; + goodprint "Temporary tables created on disk: $mycalc{'pct_temp_disk'}% (".hr_num($mystat{'Created_tmp_disk_tables'})." on disk / ".hr_num($mystat{'Created_tmp_tables'})." total)\n"; } } else { # For the sake of space, we will be quiet here From 5f1e12f11d4e45280205a42731e030e58cd6e0be Mon Sep 17 00:00:00 2001 From: Cole Turner Date: Thu, 4 Dec 2014 02:14:02 -0500 Subject: [PATCH 3/5] Adding check for autoincrement keys Not familiar with Perl, please double check. --- mysqltuner.pl | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/mysqltuner.pl b/mysqltuner.pl index 939dce7..6218c3d 100755 --- a/mysqltuner.pl +++ b/mysqltuner.pl @@ -614,6 +614,47 @@ sub check_storage_engines { } else { goodprint "Total fragmented tables: $fragtables\n"; } + + + # Auto increments + my %tblist; + # Find the maximum integer + my $maxint = `mysql $mysqllogin -Bse "SELECT ~0"`; + + # Now we build a database list, and loop through it to get storage engine stats for tables + my @dblist = `mysql $mysqllogin -Bse "SHOW DATABASES"`; + foreach my $db (@dblist) { + chomp($db); + + if(!$tblist{$db}) + { + $tblist{$db} = (); + } + + if ($db eq "information_schema") { next; } + my @ia = (0, 10); + if (!mysql_version_ge(4, 1)) { + # MySQL 3.23/4.0 keeps Data_Length in the 5th (0-based) column + @ia = (0, 9); + } + push(@{$tblist{$db}}, map { [ (split)[@ia] ] } `mysql $mysqllogin -Bse "SHOW TABLE STATUS FROM \\\`$db\\\`"`); + } + + my @dbnames = keys %tblist; + + foreach my $db (@dbnames) { + foreach my $tbl (@{$tblist{$db}}) { + my ($name, $autoincrement) = @$tbl; + + if ($autoincrement =~ /^\d+?$/) { + my $percent = ($autoincrement / $maxint) * 100; + if($percent >= 75) { + badprint "Table '$db.$name' has an autoincrement value near max capacity ($percent%)\n"; + } + } + } + } + } my %mycalc; From 3b12ccb77364fce5fe4327255fd3da53758973e3 Mon Sep 17 00:00:00 2001 From: Cole Turner Date: Thu, 4 Dec 2014 10:52:28 -0500 Subject: [PATCH 4/5] Added name to contributor list. --- mysqltuner.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysqltuner.pl b/mysqltuner.pl index 6218c3d..e5a00ed 100755 --- a/mysqltuner.pl +++ b/mysqltuner.pl @@ -29,7 +29,7 @@ # Blair Christensen Hans du Plooy Victor Trac # Everett Barnes Tom Krouper Gary Barrueto # Simon Greenaway Adam Stein Isart Montane -# Baptiste M. +# Baptiste M. Cole Turner # # Inspired by Matthew Montgomery's tuning-primer.sh script: # http://forge.mysql.com/projects/view.php?id=44 From 4f472521d76061bc04f7e86f8af04d0af1c205b2 Mon Sep 17 00:00:00 2001 From: Major Hayden Date: Thu, 4 Dec 2014 09:56:31 -0600 Subject: [PATCH 5/5] Version 1.4.0 --- mysqltuner.pl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mysqltuner.pl b/mysqltuner.pl index e5a00ed..10009d9 100755 --- a/mysqltuner.pl +++ b/mysqltuner.pl @@ -29,7 +29,7 @@ # Blair Christensen Hans du Plooy Victor Trac # Everett Barnes Tom Krouper Gary Barrueto # Simon Greenaway Adam Stein Isart Montane -# Baptiste M. Cole Turner +# Baptiste M. Cole Turner # # Inspired by Matthew Montgomery's tuning-primer.sh script: # http://forge.mysql.com/projects/view.php?id=44 @@ -41,7 +41,7 @@ use File::Spec; use Getopt::Long; # Set up a few variables for use in the script -my $tunerversion = "1.3.0"; +my $tunerversion = "1.4.0"; my (@adjvars, @generalrec); # Set defaults @@ -51,14 +51,14 @@ my %opt = ( "noinfo" => 0, "nocolor" => 0, "forcemem" => 0, - "forceswap" => 0, + "forceswap" => 0, "host" => 0, "socket" => 0, "port" => 0, "user" => 0, "pass" => 0, "skipsize" => 0, - "checkversion" => 0, + "checkversion" => 0, "buffers" => 0, );