Assembla home | Assembla project page
 

Changeset 37

Show
Ignore:
Timestamp:
06/19/08 02:33:54 (4 months ago)
Author:
major
Message:

Version bump to 0.9.1
Added checks for fragmented tables
Fixed login routine to allow zero-length passwords without re-prompting for the password repeatedly
Added workaround for wget 1.11 timestamping bug
Fixed a math error in the temporary table calculations
Fixed an error that occurred when the status variable Open_files returned zero
Added table cache change in preparation for MySQL 6.x
Thanks to Ville Skytta, Trent Hornibrook and Luuk Vosslamber for the bug reports and feature requests!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • mysqltuner.pl

    r36 r37  
    11#!/usr/bin/perl -w 
    2 # mysqltuner.pl - Version 0.9.0 
     2# mysqltuner.pl - Version 0.9.1 
    33# High Performance MySQL Tuning Script 
    44# Copyright (C) 2006-2008 Major Hayden - major@mhtx.net 
     
    2828#   Nils Breunese 
    2929#   Shawn Ashlee 
     30#   Luuk Vosslamber 
     31#   Ville Skytta 
     32#   Trent Hornibrook 
    3033# 
    3134# Inspired by Matthew Montgomery's tuning-primer.sh script: 
     
    3841 
    3942# Set up a few variables for use in the script 
    40 my $tunerversion = "0.9.0"; 
     43my $tunerversion = "0.9.1"; 
    4144my (@adjvars, @generalrec); 
    4245 
     
    222225                        chomp($password); 
    223226                        chomp($name); 
    224                         $mysqllogin = "-u $name -p'$password'"; 
     227                        $mysqllogin = "-u $name"; 
     228                        if (length($password)) { 
     229                                $mysqllogin .= " -p'$password'"; 
     230                        } 
    225231                        my $loginstatus = `mysqladmin ping $mysqllogin 2>&1`; 
    226232                        if ($loginstatus =~ /mysqld is alive/) { 
    227233                                print STDERR "\n"; 
     234                                if (! length($password)) { 
     235                                        # Did this go well because of a .my.cnf file or is there no password set? 
     236                                        my $userpath = `ls -d ~`; 
     237                                        chomp($userpath); 
     238                                        unless ( -e "$userpath/.my.cnf" ) { 
     239                                                badprint "Successfully authenticated with no password - SECURITY RISK!\n"; 
     240                                        } 
     241                                } 
    228242                                return 1; 
    229243                        } else { 
     
    261275        } 
    262276        my $update; 
     277        my $url = "http://mysqltuner.com/versioncheck.php?v=$tunerversion"; 
    263278        if (-e "/usr/bin/curl") { 
    264                 $update = `/usr/bin/curl --connect-timeout 5 http://mysqltuner.com/versioncheck.php?v=$tunerversion 2>/dev/null`; 
     279                $update = `/usr/bin/curl --connect-timeout 5 '$url' 2>/dev/null`; 
    265280                chomp($update); 
    266281        } elsif (-e "/usr/bin/wget") { 
    267                 $update = `/usr/bin/wget -T 5 -O - http://mysqltuner.com/versioncheck.php?v=$tunerversion 2>/dev/null`; 
     282                $update = `/usr/bin/wget -e timestamping=off -T 5 -O - '$url' 2>/dev/null`; 
    268283                chomp($update); 
    269284        } 
     
    307322 
    308323# Start up a ton of storage engine counts/statistics 
    309 my (%enginestats,%enginecount); 
     324my (%enginestats,%enginecount,$fragtables); 
    310325sub check_storage_engines { 
    311326        if ($opt{skipsize} eq 1) { 
     
    324339        $engines .= (defined $myvar{'have_ndbcluster'} && $myvar{'have_ndbcluster'} eq "YES")? greenwrap "+NDBCluster " : redwrap "-NDBCluster " ;       
    325340        print "$engines\n"; 
    326         if ($mysqlvermajor eq 5) { 
     341        if ($mysqlvermajor >= 5) { 
    327342                # MySQL 5 servers can have table sizes calculated quickly from information schema 
    328343                my @templist = `mysql $mysqllogin -Bse "SELECT ENGINE,SUM(DATA_LENGTH),COUNT(ENGINE) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema','mysql') GROUP BY ENGINE HAVING SUM(DATA_LENGTH) > 0 ORDER BY ENGINE ASC;"`; 
     
    333348                        $enginecount{$engine} = $count; 
    334349                } 
     350                $fragtables = `mysql $mysqllogin -Bse "SELECT COUNT(TABLE_NAME) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema','mysql') AND Data_free > 0"`; 
     351                chomp($fragtables); 
    335352        } else { 
    336353                # MySQL < 5 servers take a lot of work to get table sizes 
     
    343360                        if ($mysqlvermajor == 3 || ($mysqlvermajor == 4 && $mysqlverminor == 0)) { 
    344361                                # MySQL 3.23/4.0 keeps Data_Length in the 6th column 
    345                                 push (@tblist,`mysql $mysqllogin -Bse "SHOW TABLE STATUS FROM \\\`$db\\\`" | awk '{print \$2,\$6}'`); 
     362                                push (@tblist,`mysql $mysqllogin -Bse "SHOW TABLE STATUS FROM \\\`$db\\\`" | awk '{print \$2,\$6,\$9}'`); 
    346363                        } else { 
    347364                                # MySQL 4.1+ keeps Data_Length in the 7th column 
    348                                 push (@tblist,`mysql $mysqllogin -Bse "SHOW TABLE STATUS FROM \\\`$db\\\`" | awk '{print \$2,\$7}'`); 
     365                                push (@tblist,`mysql $mysqllogin -Bse "SHOW TABLE STATUS FROM \\\`$db\\\`" | awk '{print \$2,\$7,\$10}'`); 
    349366                        } 
    350367                } 
    351368                # Parse through the table list to generate storage engine counts/statistics 
     369                $fragtables = 0; 
    352370                foreach my $line (@tblist) { 
    353                         $line =~ /([a-zA-Z_]*)\s+(.*)/; 
     371                        chomp($line); 
     372                        $line =~ /([a-zA-Z_]*)\s+(\d+)\s+(\d+)/; 
    354373                        my $engine = $1; 
    355374                        my $size = $2; 
     375                        my $datafree = $3; 
    356376                        if ($size !~ /^\d+$/) { $size = 0; } 
    357377                        if (defined $enginestats{$engine}) { 
     
    362382                                $enginecount{$engine} = 1; 
    363383                        } 
     384                        if ($datafree > 0) { 
     385                                $fragtables++; 
     386                        } 
    364387                } 
    365388        } 
     
    379402                badprint "ISAM is enabled but isn't being used\n"; 
    380403                push(@generalrec,"Add skip-isam to MySQL configuration to disable ISAM"); 
     404        } 
     405        # Fragmented tables 
     406        if ($fragtables > 0) { 
     407                badprint "Total fragmented tables: $fragtables\n"; 
     408                push(@generalrec,"Run OPTIMIZE TABLE to defragment tables for better performance"); 
     409        } else { 
     410                goodprint "Total fragmented tables: $fragtables\n"; 
    381411        } 
    382412} 
     
    454484        if ($mystat{'Created_tmp_tables'} > 0) { 
    455485                if ($mystat{'Created_tmp_disk_tables'} > 0) { 
    456                         $mycalc{'pct_temp_disk'} = int(($mystat{'Created_tmp_disk_tables'} / $mystat{'Created_tmp_tables'}) * 100); 
     486                        $mycalc{'pct_temp_disk'} = int(($mystat{'Created_tmp_disk_tables'} / ($mystat{'Created_tmp_tables'} + $mystat{'Created_tmp_disk_tables'})) * 100); 
    457487                } else { 
    458488                        $mycalc{'pct_temp_disk'} = 0; 
     
    468498         
    469499        # Open files 
    470         if ($mystat{'Open_files'} > 0 && $myvar{'open_files_limit'} > 0) { 
     500        if ($myvar{'open_files_limit'} > 0) { 
    471501                $mycalc{'pct_files_open'} = int($mystat{'Open_files'}*100/$myvar{'open_files_limit'}); 
    472502        } 
     
    671701 
    672702        # Open files 
    673         if ($myvar{'open_files_limit'} > 0) { 
     703        if (defined $mycalc{'pct_files_open'}) { 
    674704                if ($mycalc{'pct_files_open'} > 85) { 
    675705                        badprint "Open file limit used: $mycalc{'pct_files_open'}%\n";