Changeset 37
- Timestamp:
- 06/19/08 02:33:54 (6 months ago)
- Files:
-
- mysqltuner.pl (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
mysqltuner.pl
r36 r37 1 1 #!/usr/bin/perl -w 2 # mysqltuner.pl - Version 0.9. 02 # mysqltuner.pl - Version 0.9.1 3 3 # High Performance MySQL Tuning Script 4 4 # Copyright (C) 2006-2008 Major Hayden - major@mhtx.net … … 28 28 # Nils Breunese 29 29 # Shawn Ashlee 30 # Luuk Vosslamber 31 # Ville Skytta 32 # Trent Hornibrook 30 33 # 31 34 # Inspired by Matthew Montgomery's tuning-primer.sh script: … … 38 41 39 42 # Set up a few variables for use in the script 40 my $tunerversion = "0.9. 0";43 my $tunerversion = "0.9.1"; 41 44 my (@adjvars, @generalrec); 42 45 … … 222 225 chomp($password); 223 226 chomp($name); 224 $mysqllogin = "-u $name -p'$password'"; 227 $mysqllogin = "-u $name"; 228 if (length($password)) { 229 $mysqllogin .= " -p'$password'"; 230 } 225 231 my $loginstatus = `mysqladmin ping $mysqllogin 2>&1`; 226 232 if ($loginstatus =~ /mysqld is alive/) { 227 233 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 } 228 242 return 1; 229 243 } else { … … 261 275 } 262 276 my $update; 277 my $url = "http://mysqltuner.com/versioncheck.php?v=$tunerversion"; 263 278 if (-e "/usr/bin/curl") { 264 $update = `/usr/bin/curl --connect-timeout 5 http://mysqltuner.com/versioncheck.php?v=$tunerversion2>/dev/null`;279 $update = `/usr/bin/curl --connect-timeout 5 '$url' 2>/dev/null`; 265 280 chomp($update); 266 281 } elsif (-e "/usr/bin/wget") { 267 $update = `/usr/bin/wget - T 5 -O - http://mysqltuner.com/versioncheck.php?v=$tunerversion2>/dev/null`;282 $update = `/usr/bin/wget -e timestamping=off -T 5 -O - '$url' 2>/dev/null`; 268 283 chomp($update); 269 284 } … … 307 322 308 323 # Start up a ton of storage engine counts/statistics 309 my (%enginestats,%enginecount );324 my (%enginestats,%enginecount,$fragtables); 310 325 sub check_storage_engines { 311 326 if ($opt{skipsize} eq 1) { … … 324 339 $engines .= (defined $myvar{'have_ndbcluster'} && $myvar{'have_ndbcluster'} eq "YES")? greenwrap "+NDBCluster " : redwrap "-NDBCluster " ; 325 340 print "$engines\n"; 326 if ($mysqlvermajor eq5) {341 if ($mysqlvermajor >= 5) { 327 342 # MySQL 5 servers can have table sizes calculated quickly from information schema 328 343 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;"`; … … 333 348 $enginecount{$engine} = $count; 334 349 } 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); 335 352 } else { 336 353 # MySQL < 5 servers take a lot of work to get table sizes … … 343 360 if ($mysqlvermajor == 3 || ($mysqlvermajor == 4 && $mysqlverminor == 0)) { 344 361 # 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}'`); 346 363 } else { 347 364 # 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}'`); 349 366 } 350 367 } 351 368 # Parse through the table list to generate storage engine counts/statistics 369 $fragtables = 0; 352 370 foreach my $line (@tblist) { 353 $line =~ /([a-zA-Z_]*)\s+(.*)/; 371 chomp($line); 372 $line =~ /([a-zA-Z_]*)\s+(\d+)\s+(\d+)/; 354 373 my $engine = $1; 355 374 my $size = $2; 375 my $datafree = $3; 356 376 if ($size !~ /^\d+$/) { $size = 0; } 357 377 if (defined $enginestats{$engine}) { … … 362 382 $enginecount{$engine} = 1; 363 383 } 384 if ($datafree > 0) { 385 $fragtables++; 386 } 364 387 } 365 388 } … … 379 402 badprint "ISAM is enabled but isn't being used\n"; 380 403 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"; 381 411 } 382 412 } … … 454 484 if ($mystat{'Created_tmp_tables'} > 0) { 455 485 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); 457 487 } else { 458 488 $mycalc{'pct_temp_disk'} = 0; … … 468 498 469 499 # Open files 470 if ($my stat{'Open_files'} > 0 && $myvar{'open_files_limit'} > 0) {500 if ($myvar{'open_files_limit'} > 0) { 471 501 $mycalc{'pct_files_open'} = int($mystat{'Open_files'}*100/$myvar{'open_files_limit'}); 472 502 } … … 671 701 672 702 # Open files 673 if ( $myvar{'open_files_limit'} > 0) {703 if (defined $mycalc{'pct_files_open'}) { 674 704 if ($mycalc{'pct_files_open'} > 85) { 675 705 badprint "Open file limit used: $mycalc{'pct_files_open'}%\n";