From 5f1e12f11d4e45280205a42731e030e58cd6e0be Mon Sep 17 00:00:00 2001 From: Cole Turner Date: Thu, 4 Dec 2014 02:14:02 -0500 Subject: [PATCH 1/2] 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 2/2] 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