Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 891 lines (839 sloc) 39.054 kb
c8c2dd9 @major Bumped version to 0.9.9
authored
1 #!/usr/bin/perl -w
a462d4d @major Version bump to 1.0.0
authored
2 # mysqltuner.pl - Version 1.0.0
c8c2dd9 @major Bumped version to 0.9.9
authored
3 # High Performance MySQL Tuning Script
4 # Copyright (C) 2006-2008 Major Hayden - major@mhtx.net
5 #
6 # For the latest updates, please visit http://mysqltuner.com/
7 # Subversion repository available at http://tools.assembla.com/svn/mysqltuner/
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #
22 # This project would not be possible without help from:
23 # Matthew Montgomery Paul Kehrer
24 # Dave Burgess Jonathan Hinds
25 # Mike Jackson Nils Breunese
26 # Shawn Ashlee Luuk Vosslamber
27 # Ville Skytta Trent Hornibrook
28 # Jason Gill Mark Imbriaco
29 # Greg Eden Aubin Galinotti
30 # Giovanni Bechis Bill Bradford
a462d4d @major Version bump to 1.0.0
authored
31 # Ryan Novosielski Michael Scheidell
32 # Blair Christensen Hans du Plooy
33 # Victor Trac Everett Barnes
a2bb3ab @major Fixed an issue where MEMORY tables would appear in the fragmented table ...
authored
34 # Tom Krouper Gary Barrueto
fff47e9 @major Fixed a Solaris awk bug, found a more reliable way to get the home direc...
authored
35 # Simon Greenaway Adam Stein
c8c2dd9 @major Bumped version to 0.9.9
authored
36 #
37 # Inspired by Matthew Montgomery's tuning-primer.sh script:
38 # http://forge.mysql.com/projects/view.php?id=44
39 #
40 use strict;
41 use warnings;
42 use diagnostics;
43 use Getopt::Long;
44
45 # Set up a few variables for use in the script
a462d4d @major Version bump to 1.0.0
authored
46 my $tunerversion = "1.0.0";
c8c2dd9 @major Bumped version to 0.9.9
authored
47 my (@adjvars, @generalrec);
48
49 # Set defaults
50 my %opt = (
51 "nobad" => 0,
52 "nogood" => 0,
53 "noinfo" => 0,
54 "nocolor" => 0,
55 "forcemem" => 0,
56 "forceswap" => 0,
57 "host" => 0,
58 "socket" => 0,
59 "port" => 0,
60 "user" => 0,
61 "pass" => 0,
62 "skipsize" => 0,
63 "checkversion" => 0,
64 );
65
66 # Gather the options from the command line
67 GetOptions(\%opt,
68 'nobad',
69 'nogood',
70 'noinfo',
71 'nocolor',
72 'forcemem=i',
73 'forceswap=i',
74 'host=s',
75 'socket=s',
76 'port=i',
77 'user=s',
78 'pass=s',
79 'skipsize',
80 'checkversion',
81 'help',
82 );
83
84 if (defined $opt{'help'} && $opt{'help'} == 1) { usage(); }
85
86 sub usage {
87 # Shown with --help option passed
88 print "\n".
89 " MySQLTuner $tunerversion - MySQL High Performance Tuning Script\n".
90 " Bug reports, feature requests, and downloads at http://mysqltuner.com/\n".
91 " Maintained by Major Hayden (major\@mhtx.net) - Licensed under GPL\n".
92 "\n".
93 " Important Usage Guidelines:\n".
94 " To run the script with the default options, run the script without arguments\n".
95 " Allow MySQL server to run for at least 24-48 hours before trusting suggestions\n".
96 " Some routines may require root level privileges (script will provide warnings)\n".
97 " You must provide the remote server's total memory when connecting to other servers\n".
98 "\n".
99 " Connection and Authentication\n".
100 " --host <hostname> Connect to a remote host to perform tests (default: localhost)\n".
101 " --socket <socket> Use a different socket for a local connection\n".
102 " --port <port> Port to use for connection (default: 3306)\n".
103 " --user <username> Username to use for authentication\n".
104 " --pass <password> Password to use for authentication\n".
105 "\n".
106 " Performance and Reporting Options\n".
107 " --skipsize Don't enumerate tables and their types/sizes (default: on)\n".
108 " (Recommended for servers with many tables)\n".
109 " --checkversion Check for updates to MySQLTuner (default: don't check)\n".
110 " --forcemem <size> Amount of RAM installed in megabytes\n".
111 " --forceswap <size> Amount of swap memory configured in megabytes\n".
112 "\n".
113 " Output Options:\n".
114 " --nogood Remove OK responses\n".
115 " --nobad Remove negative/suggestion responses\n".
116 " --noinfo Remove informational responses\n".
117 " --nocolor Don't print output in color\n".
118 "\n";
119 exit;
120 }
121
122 # Setting up the colors for the print styles
fff47e9 @major Fixed a Solaris awk bug, found a more reliable way to get the home direc...
authored
123 my $good = ($opt{nocolor} == 0)? "[\e[0;32mOK\e[0m]" : "[OK]" ;
124 my $bad = ($opt{nocolor} == 0)? "[\e[0;31m!!\e[0m]" : "[!!]" ;
125 my $info = ($opt{nocolor} == 0)? "[\e[0;34m--\e[0m]" : "[--]" ;
c8c2dd9 @major Bumped version to 0.9.9
authored
126
127 # Functions that handle the print styles
128 sub goodprint { print $good." ".$_[0] unless ($opt{nogood} == 1); }
129 sub infoprint { print $info." ".$_[0] unless ($opt{noinfo} == 1); }
130 sub badprint { print $bad." ".$_[0] unless ($opt{nobad} == 1); }
fff47e9 @major Fixed a Solaris awk bug, found a more reliable way to get the home direc...
authored
131 sub redwrap { return ($opt{nocolor} == 0)? "\e[0;31m".$_[0]."\e[0m" : $_[0] ; }
132 sub greenwrap { return ($opt{nocolor} == 0)? "\e[0;32m".$_[0]."\e[0m" : $_[0] ; }
c8c2dd9 @major Bumped version to 0.9.9
authored
133
134 # Calculates the parameter passed in bytes, and then rounds it to one decimal place
135 sub hr_bytes {
136 my $num = shift;
137 if ($num >= (1024**3)) { #GB
138 return sprintf("%.1f",($num/(1024**3)))."G";
139 } elsif ($num >= (1024**2)) { #MB
140 return sprintf("%.1f",($num/(1024**2)))."M";
141 } elsif ($num >= 1024) { #KB
142 return sprintf("%.1f",($num/1024))."K";
143 } else {
144 return $num."B";
145 }
146 }
147
148 # Calculates the parameter passed in bytes, and then rounds it to the nearest integer
149 sub hr_bytes_rnd {
150 my $num = shift;
151 if ($num >= (1024**3)) { #GB
152 return int(($num/(1024**3)))."G";
153 } elsif ($num >= (1024**2)) { #MB
154 return int(($num/(1024**2)))."M";
155 } elsif ($num >= 1024) { #KB
156 return int(($num/1024))."K";
157 } else {
158 return $num."B";
159 }
160 }
161
162 # Calculates the parameter passed to the nearest power of 1000, then rounds it to the nearest integer
163 sub hr_num {
164 my $num = shift;
165 if ($num >= (1000**3)) { # Billions
166 return int(($num/(1000**3)))."B";
167 } elsif ($num >= (1000**2)) { # Millions
168 return int(($num/(1000**2)))."M";
169 } elsif ($num >= 1000) { # Thousands
170 return int(($num/1000))."K";
171 } else {
172 return $num;
173 }
174 }
175
176 # Calculates uptime to display in a more attractive form
177 sub pretty_uptime {
178 my $uptime = shift;
179 my $seconds = $uptime % 60;
180 my $minutes = int(($uptime % 3600) / 60);
181 my $hours = int(($uptime % 86400) / (3600));
182 my $days = int($uptime / (86400));
183 my $uptimestring;
184 if ($days > 0) {
185 $uptimestring = "${days}d ${hours}h ${minutes}m ${seconds}s";
186 } elsif ($hours > 0) {
187 $uptimestring = "${hours}h ${minutes}m ${seconds}s";
188 } elsif ($minutes > 0) {
189 $uptimestring = "${minutes}m ${seconds}s";
190 } else {
191 $uptimestring = "${seconds}s";
192 }
193 return $uptimestring;
194 }
195
196 # Retrieves the memory installed on this machine
197 my ($physical_memory,$swap_memory,$duflags);
198 sub os_setup {
199 sub memerror {
200 badprint "Unable to determine total memory/swap; use '--forcemem' and '--forceswap'\n";
201 exit;
202 }
203 my $os = `uname`;
204 $duflags = ($os =~ /Linux/) ? '-b' : '';
205 if ($opt{'forcemem'} > 0) {
206 $physical_memory = $opt{'forcemem'} * 1048576;
207 infoprint "Assuming $opt{'forcemem'} MB of physical memory\n";
208 if ($opt{'forceswap'} > 0) {
209 $swap_memory = $opt{'forceswap'} * 1048576;
210 infoprint "Assuming $opt{'forceswap'} MB of swap space\n";
211 } else {
212 $swap_memory = 0;
213 badprint "Assuming 0 MB of swap space (use --forceswap to specify)\n";
214 }
215 } else {
216 if ($os =~ /Linux/) {
217 $physical_memory = `free -b | grep Mem | awk '{print \$2}'` or memerror;
218 $swap_memory = `free -b | grep Swap | awk '{print \$2}'` or memerror;
219 } elsif ($os =~ /Darwin/) {
220 $physical_memory = `sysctl -n hw.memsize` or memerror;
221 $swap_memory = `sysctl -n vm.swapusage | awk '{print \$3}' | sed 's/\..*\$//'` or memerror;
222 } elsif ($os =~ /NetBSD|OpenBSD/) {
223 $physical_memory = `sysctl -n hw.physmem` or memerror;
c0ab5bc @major Version bump to 1.0.0-rc1
authored
224 if ($physical_memory < 0) {
225 $physical_memory = `sysctl -n hw.physmem64` or memerror;
226 }
c8c2dd9 @major Bumped version to 0.9.9
authored
227 $swap_memory = `swapctl -l | grep '^/' | awk '{ s+= \$2 } END { print s }'` or memerror;
228 } elsif ($os =~ /BSD/) {
229 $physical_memory = `sysctl -n hw.realmem`;
230 $swap_memory = `swapinfo | grep '^/' | awk '{ s+= \$2 } END { print s }'`;
c0ab5bc @major Version bump to 1.0.0-rc1
authored
231 } elsif ($os =~ /SunOS/) {
fff47e9 @major Fixed a Solaris awk bug, found a more reliable way to get the home direc...
authored
232 $physical_memory = `/usr/sbin/prtconf | grep Memory | cut -f 3 -d ' '` or memerror;
c0ab5bc @major Version bump to 1.0.0-rc1
authored
233 chomp($physical_memory);
234 $physical_memory = $physical_memory*1024*1024;
c8c2dd9 @major Bumped version to 0.9.9
authored
235 }
236 }
237 chomp($physical_memory);
238 }
239
240 # Checks to see if a MySQL login is possible
241 my ($mysqllogin,$doremote,$remotestring);
242 sub mysql_setup {
243 $doremote = 0;
244 $remotestring = '';
245 my $command = `which mysqladmin`;
246 chomp($command);
247 if (! -e $command) {
248 badprint "Unable to find mysqladmin in your \$PATH. Is MySQL installed?\n";
249 exit;
250 }
251 # Are we being asked to connect via a socket?
252 if ($opt{socket} ne 0) {
253 $remotestring = " -S $opt{socket}";
254 }
255 # Are we being asked to connect to a remote server?
256 if ($opt{host} ne 0) {
257 chomp($opt{host});
258 $opt{port} = ($opt{port} eq 0)? 3306 : $opt{port} ;
259 # If we're doing a remote connection, but forcemem wasn't specified, we need to exit
260 if ($opt{'forcemem'} eq 0) {
261 badprint "The --forcemem option is required for remote connections\n";
262 exit;
263 }
264 infoprint "Performing tests on $opt{host}:$opt{port}\n";
265 $remotestring = " -h $opt{host} -P $opt{port}";
266 $doremote = 1;
267 }
268 # Did we already get a username and password passed on the command line?
269 if ($opt{user} ne 0 and $opt{pass} ne 0) {
270 $mysqllogin = "-u $opt{user} -p'$opt{pass}'".$remotestring;
271 my $loginstatus = `mysqladmin ping $mysqllogin 2>&1`;
272 if ($loginstatus =~ /mysqld is alive/) {
273 goodprint "Logged in using credentials passed on the command line\n";
274 return 1;
275 } else {
276 badprint "Attempted to use login credentials, but they were invalid\n";
277 exit 0;
278 }
279 }
280 if ( -r "/etc/psa/.psa.shadow" and $doremote == 0 ) {
281 # It's a Plesk box, use the available credentials
282 $mysqllogin = "-u admin -p`cat /etc/psa/.psa.shadow`";
283 my $loginstatus = `mysqladmin ping $mysqllogin 2>&1`;
284 unless ($loginstatus =~ /mysqld is alive/) {
285 badprint "Attempted to use login credentials from Plesk, but they failed.\n";
286 exit 0;
287 }
288 } else {
289 # It's not Plesk, we should try a login
290 my $loginstatus = `mysqladmin $remotestring ping 2>&1`;
291 if ($loginstatus =~ /mysqld is alive/) {
292 # Login went just fine
c0ab5bc @major Version bump to 1.0.0-rc1
authored
293 $mysqllogin = " $remotestring ";
c8c2dd9 @major Bumped version to 0.9.9
authored
294 # Did this go well because of a .my.cnf file or is there no password set?
fff47e9 @major Fixed a Solaris awk bug, found a more reliable way to get the home direc...
authored
295 my $userpath = `printenv HOME`;
c8c2dd9 @major Bumped version to 0.9.9
authored
296 if (length($userpath) > 0) {
297 chomp($userpath);
298 }
299 unless ( -e "${userpath}/.my.cnf" ) {
300 badprint "Successfully authenticated with no password - SECURITY RISK!\n";
301 }
302 return 1;
303 } else {
304 print STDERR "Please enter your MySQL administrative login: ";
305 my $name = <>;
306 print STDERR "Please enter your MySQL administrative password: ";
307 system("stty -echo");
308 my $password = <>;
309 system("stty echo");
310 chomp($password);
311 chomp($name);
312 $mysqllogin = "-u $name";
313 if (length($password) > 0) {
314 $mysqllogin .= " -p'$password'";
315 }
316 $mysqllogin .= $remotestring;
317 my $loginstatus = `mysqladmin ping $mysqllogin 2>&1`;
318 if ($loginstatus =~ /mysqld is alive/) {
319 print STDERR "\n";
320 if (! length($password)) {
321 # Did this go well because of a .my.cnf file or is there no password set?
322 my $userpath = `ls -d ~`;
323 chomp($userpath);
324 unless ( -e "$userpath/.my.cnf" ) {
325 badprint "Successfully authenticated with no password - SECURITY RISK!\n";
326 }
327 }
328 return 1;
329 } else {
330 print "\n".$bad." Attempted to use login credentials, but they were invalid.\n";
331 exit 0;
332 }
333 exit 0;
334 }
335 }
336 }
337
338 # Populates all of the variable and status hashes
339 my (%mystat,%myvar,$dummyselect);
340 sub get_all_vars {
341 # We need to initiate at least one query so that our data is useable
342 $dummyselect = `mysql $mysqllogin -Bse "SELECT VERSION();"`;
343 my @mysqlvarlist = `mysql $mysqllogin -Bse "SHOW /*!50000 GLOBAL */ VARIABLES;"`;
344 foreach my $line (@mysqlvarlist) {
345 $line =~ /([a-zA-Z_]*)\s*(.*)/;
346 $myvar{$1} = $2;
347 }
348 my @mysqlstatlist = `mysql $mysqllogin -Bse "SHOW /*!50000 GLOBAL */ STATUS;"`;
349 foreach my $line (@mysqlstatlist) {
350 $line =~ /([a-zA-Z_]*)\s*(.*)/;
351 $mystat{$1} = $2;
352 }
353 }
354
355 # Checks for updates to MySQLTuner
356 sub validate_tuner_version {
357 print "\n-------- General Statistics --------------------------------------------------\n";
358 if ($opt{checkversion} eq 0) {
359 infoprint "Skipped version check for MySQLTuner script\n";
360 return;
361 }
362 my $update;
363 my $url = "http://mysqltuner.com/versioncheck.php?v=$tunerversion";
364 if (-e "/usr/bin/curl") {
365 $update = `/usr/bin/curl --connect-timeout 5 '$url' 2>/dev/null`;
366 chomp($update);
367 } elsif (-e "/usr/bin/wget") {
368 $update = `/usr/bin/wget -e timestamping=off -T 5 -O - '$url' 2>/dev/null`;
369 chomp($update);
370 }
371 if ($update eq 1) {
372 badprint "There is a new version of MySQLTuner available\n";
373 } elsif ($update eq 0) {
374 goodprint "You have the latest version of MySQLTuner\n";
375 } else {
376 infoprint "Unable to check for the latest MySQLTuner version\n";
377 }
378 }
379
380 # Checks for supported or EOL'ed MySQL versions
381 my ($mysqlvermajor,$mysqlverminor);
382 sub validate_mysql_version {
383 ($mysqlvermajor,$mysqlverminor) = $myvar{'version'} =~ /(\d)\.(\d)/;
384 if ($mysqlvermajor < 5) {
385 badprint "Your MySQL version ".$myvar{'version'}." is EOL software! Upgrade soon!\n";
386 } elsif ($mysqlvermajor == 5) {
387 goodprint "Currently running supported MySQL version ".$myvar{'version'}."\n";
388 } else {
389 badprint "Currently running unsupported MySQL version ".$myvar{'version'}."\n";
390 }
391 }
392
393 # Checks for 32-bit boxes with more than 2GB of RAM
394 my ($arch);
395 sub check_architecture {
396 if ($doremote eq 1) { return; }
c0ab5bc @major Version bump to 1.0.0-rc1
authored
397 if (`uname` =~ /SunOS/ && `isainfo -b` =~ /64/) {
398 $arch = 64;
399 goodprint "Operating on 64-bit architecture\n";
400 } elsif (`uname` !~ /SunOS/ && `uname -m` =~ /64/) {
c8c2dd9 @major Bumped version to 0.9.9
authored
401 $arch = 64;
402 goodprint "Operating on 64-bit architecture\n";
403 } else {
404 $arch = 32;
405 if ($physical_memory > 2147483648) {
a462d4d @major Version bump to 1.0.0
authored
406 badprint "Switch to 64-bit OS - MySQL cannot currently use all of your RAM\n";
c8c2dd9 @major Bumped version to 0.9.9
authored
407 } else {
408 goodprint "Operating on 32-bit architecture with less than 2GB RAM\n";
409 }
410 }
411 }
412
413 # Start up a ton of storage engine counts/statistics
414 my (%enginestats,%enginecount,$fragtables);
415 sub check_storage_engines {
416 if ($opt{skipsize} eq 1) {
417 print "\n-------- Storage Engine Statistics -------------------------------------------\n";
418 infoprint "Skipped due to --skipsize option\n";
419 return;
420 }
421 print "\n-------- Storage Engine Statistics -------------------------------------------\n";
422 infoprint "Status: ";
423 my $engines;
424 $engines .= (defined $myvar{'have_archive'} && $myvar{'have_archive'} eq "YES")? greenwrap "+Archive " : redwrap "-Archive " ;
425 $engines .= (defined $myvar{'have_bdb'} && $myvar{'have_bdb'} eq "YES")? greenwrap "+BDB " : redwrap "-BDB " ;
426 $engines .= (defined $myvar{'have_federated'} && $myvar{'have_federated'} eq "YES")? greenwrap "+Federated " : redwrap "-Federated " ;
427 $engines .= (defined $myvar{'have_innodb'} && $myvar{'have_innodb'} eq "YES")? greenwrap "+InnoDB " : redwrap "-InnoDB " ;
428 $engines .= (defined $myvar{'have_isam'} && $myvar{'have_isam'} eq "YES")? greenwrap "+ISAM " : redwrap "-ISAM " ;
429 $engines .= (defined $myvar{'have_ndbcluster'} && $myvar{'have_ndbcluster'} eq "YES")? greenwrap "+NDBCluster " : redwrap "-NDBCluster " ;
430 print "$engines\n";
431 if ($mysqlvermajor >= 5) {
432 # MySQL 5 servers can have table sizes calculated quickly from information schema
e419c79 @major Fixed an issue where null storage engines appeared when querying INFORMA...
authored
433 my @templist = `mysql $mysqllogin -Bse "SELECT ENGINE,SUM(DATA_LENGTH),COUNT(ENGINE) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema','mysql') AND ENGINE IS NOT NULL GROUP BY ENGINE ORDER BY ENGINE ASC;"`;
c8c2dd9 @major Bumped version to 0.9.9
authored
434 foreach my $line (@templist) {
435 my ($engine,$size,$count);
436 ($engine,$size,$count) = $line =~ /([a-zA-Z_]*)\s+(\d+)\s+(\d+)/;
e328934 @major Fixed an issue with NULL storage engines appearing on some servers.
authored
437 if (!defined($size)) { next; }
c8c2dd9 @major Bumped version to 0.9.9
authored
438 $enginestats{$engine} = $size;
439 $enginecount{$engine} = $count;
440 }
a2bb3ab @major Fixed an issue where MEMORY tables would appear in the fragmented table ...
authored
441 $fragtables = `mysql $mysqllogin -Bse "SELECT COUNT(TABLE_NAME) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema','mysql') AND Data_free > 0 AND NOT ENGINE='MEMORY';"`;
c8c2dd9 @major Bumped version to 0.9.9
authored
442 chomp($fragtables);
443 } else {
444 # MySQL < 5 servers take a lot of work to get table sizes
445 my @tblist;
446 # Now we build a database list, and loop through it to get storage engine stats for tables
447 my @dblist = `mysql $mysqllogin -Bse "SHOW DATABASES"`;
448 foreach my $db (@dblist) {
449 chomp($db);
450 if ($db eq "information_schema") { next; }
451 if ($mysqlvermajor == 3 || ($mysqlvermajor == 4 && $mysqlverminor == 0)) {
452 # MySQL 3.23/4.0 keeps Data_Length in the 6th column
453 push (@tblist,`mysql $mysqllogin -Bse "SHOW TABLE STATUS FROM \\\`$db\\\`" | awk '{print \$2,\$6,\$9}'`);
454 } else {
455 # MySQL 4.1+ keeps Data_Length in the 7th column
456 push (@tblist,`mysql $mysqllogin -Bse "SHOW TABLE STATUS FROM \\\`$db\\\`" | awk '{print \$2,\$7,\$10}'`);
457 }
458 }
459 # Parse through the table list to generate storage engine counts/statistics
460 $fragtables = 0;
461 foreach my $line (@tblist) {
462 chomp($line);
463 $line =~ /([a-zA-Z_]*)\s+(\d+)\s+(\d+)/;
464 my $engine = $1;
465 my $size = $2;
466 my $datafree = $3;
467 if ($size !~ /^\d+$/) { $size = 0; }
468 if (defined $enginestats{$engine}) {
469 $enginestats{$engine} += $size;
470 $enginecount{$engine} += 1;
471 } else {
472 $enginestats{$engine} = $size;
473 $enginecount{$engine} = 1;
474 }
475 if ($datafree > 0) {
476 $fragtables++;
477 }
478 }
479 }
480 while (my ($engine,$size) = each(%enginestats)) {
481 infoprint "Data in $engine tables: ".hr_bytes_rnd($size)." (Tables: ".$enginecount{$engine}.")"."\n";
482 }
483 # If the storage engine isn't being used, recommend it to be disabled
484 if (!defined $enginestats{'InnoDB'} && defined $myvar{'have_innodb'} && $myvar{'have_innodb'} eq "YES") {
485 badprint "InnoDB is enabled but isn't being used\n";
486 push(@generalrec,"Add skip-innodb to MySQL configuration to disable InnoDB");
487 }
488 if (!defined $enginestats{'BerkeleyDB'} && defined $myvar{'have_bdb'} && $myvar{'have_bdb'} eq "YES") {
489 badprint "BDB is enabled but isn't being used\n";
490 push(@generalrec,"Add skip-bdb to MySQL configuration to disable BDB");
491 }
492 if (!defined $enginestats{'ISAM'} && defined $myvar{'have_isam'} && $myvar{'have_isam'} eq "YES") {
493 badprint "ISAM is enabled but isn't being used\n";
c0ab5bc @major Version bump to 1.0.0-rc1
authored
494 push(@generalrec,"Add skip-isam to MySQL configuration to disable ISAM (MySQL > 4.1.0)");
c8c2dd9 @major Bumped version to 0.9.9
authored
495 }
496 # Fragmented tables
497 if ($fragtables > 0) {
498 badprint "Total fragmented tables: $fragtables\n";
499 push(@generalrec,"Run OPTIMIZE TABLE to defragment tables for better performance");
500 } else {
501 goodprint "Total fragmented tables: $fragtables\n";
502 }
503 }
504
505 my %mycalc;
506 sub calculations {
507 if ($mystat{'Questions'} < 1) {
508 badprint "Your server has not answered any queries - cannot continue...";
509 exit 0;
510 }
511 # Per-thread memory
512 if ($mysqlvermajor > 3) {
513 $mycalc{'per_thread_buffers'} = $myvar{'read_buffer_size'} + $myvar{'read_rnd_buffer_size'} + $myvar{'sort_buffer_size'} + $myvar{'thread_stack'} + $myvar{'join_buffer_size'};
514 } else {
515 $mycalc{'per_thread_buffers'} = $myvar{'record_buffer'} + $myvar{'record_rnd_buffer'} + $myvar{'sort_buffer'} + $myvar{'thread_stack'} + $myvar{'join_buffer_size'};
516 }
517 $mycalc{'total_per_thread_buffers'} = $mycalc{'per_thread_buffers'} * $myvar{'max_connections'};
518 $mycalc{'max_total_per_thread_buffers'} = $mycalc{'per_thread_buffers'} * $mystat{'Max_used_connections'};
519
520 # Server-wide memory
521 $mycalc{'max_tmp_table_size'} = ($myvar{'tmp_table_size'} > $myvar{'max_heap_table_size'}) ? $myvar{'max_heap_table_size'} : $myvar{'tmp_table_size'} ;
522 $mycalc{'server_buffers'} = $myvar{'key_buffer_size'} + $mycalc{'max_tmp_table_size'};
523 $mycalc{'server_buffers'} += (defined $myvar{'innodb_buffer_pool_size'}) ? $myvar{'innodb_buffer_pool_size'} : 0 ;
524 $mycalc{'server_buffers'} += (defined $myvar{'innodb_additional_mem_pool_size'}) ? $myvar{'innodb_additional_mem_pool_size'} : 0 ;
525 $mycalc{'server_buffers'} += (defined $myvar{'innodb_log_buffer_size'}) ? $myvar{'innodb_log_buffer_size'} : 0 ;
526 $mycalc{'server_buffers'} += (defined $myvar{'query_cache_size'}) ? $myvar{'query_cache_size'} : 0 ;
527
528 # Global memory
529 $mycalc{'max_used_memory'} = $mycalc{'server_buffers'} + $mycalc{"max_total_per_thread_buffers"};
530 $mycalc{'total_possible_used_memory'} = $mycalc{'server_buffers'} + $mycalc{'total_per_thread_buffers'};
531 $mycalc{'pct_physical_memory'} = int(($mycalc{'total_possible_used_memory'} * 100) / $physical_memory);
532
533 # Slow queries
534 $mycalc{'pct_slow_queries'} = int(($mystat{'Slow_queries'}/$mystat{'Questions'}) * 100);
535
536 # Connections
537 $mycalc{'pct_connections_used'} = int(($mystat{'Max_used_connections'}/$myvar{'max_connections'}) * 100);
538 $mycalc{'pct_connections_used'} = ($mycalc{'pct_connections_used'} > 100) ? 100 : $mycalc{'pct_connections_used'} ;
539
540 # Key buffers
541 if ($mysqlvermajor > 3 && !($mysqlvermajor == 4 && $mysqlverminor == 0)) {
542 $mycalc{'pct_key_buffer_used'} = sprintf("%.1f",(1 - (($mystat{'Key_blocks_unused'} * $myvar{'key_cache_block_size'}) / $myvar{'key_buffer_size'})) * 100);
543 }
544 if ($mystat{'Key_read_requests'} > 0) {
545 $mycalc{'pct_keys_from_mem'} = sprintf("%.1f",(100 - (($mystat{'Key_reads'} / $mystat{'Key_read_requests'}) * 100)));
e425897 @major Fixed an issue where the percentage of keys pulled from memory would not...
authored
546 } else {
547 $mycalc{'pct_keys_from_mem'} = 0;
c8c2dd9 @major Bumped version to 0.9.9
authored
548 }
549 if ($doremote eq 0 and $mysqlvermajor < 5) {
550 $mycalc{'total_myisam_indexes'} = `find $myvar{'datadir'} -name '*.MYI' 2>&1 | xargs du -L $duflags '{}' 2>&1 | awk '{ s += \$1 } END { printf (\"%d\",s) }'`;
551 } elsif ($mysqlvermajor >= 5) {
62e42e3 @major When counting index size for MyISAM tables, the INFORMATION_SCHEMA query...
authored
552 $mycalc{'total_myisam_indexes'} = `mysql $mysqllogin -Bse "SELECT IFNULL(SUM(INDEX_LENGTH),0) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema') AND ENGINE = 'MyISAM';"`;
c8c2dd9 @major Bumped version to 0.9.9
authored
553 }
554 if (defined $mycalc{'total_myisam_indexes'} and $mycalc{'total_myisam_indexes'} =~ /^0\n$/) {
555 $mycalc{'total_myisam_indexes'} = "fail";
556 } elsif (defined $mycalc{'total_myisam_indexes'}) {
557 chomp($mycalc{'total_myisam_indexes'});
558 }
559
560 # Query cache
561 if ($mysqlvermajor > 3) {
562 $mycalc{'query_cache_efficiency'} = sprintf("%.1f",($mystat{'Qcache_hits'} / ($mystat{'Com_select'} + $mystat{'Qcache_hits'})) * 100);
563 if ($myvar{'query_cache_size'}) {
564 $mycalc{'pct_query_cache_used'} = sprintf("%.1f",100 - ($mystat{'Qcache_free_memory'} / $myvar{'query_cache_size'}) * 100);
565 }
566 if ($mystat{'Qcache_lowmem_prunes'} == 0) {
567 $mycalc{'query_cache_prunes_per_day'} = 0;
568 } else {
569 $mycalc{'query_cache_prunes_per_day'} = int($mystat{'Qcache_lowmem_prunes'} / ($mystat{'Uptime'}/86400));
570 }
571 }
572
573 # Sorting
574 $mycalc{'total_sorts'} = $mystat{'Sort_scan'} + $mystat{'Sort_range'};
575 if ($mycalc{'total_sorts'} > 0) {
576 $mycalc{'pct_temp_sort_table'} = int(($mystat{'Sort_merge_passes'} / $mycalc{'total_sorts'}) * 100);
577 }
578
579 # Joins
580 $mycalc{'joins_without_indexes'} = $mystat{'Select_range_check'} + $mystat{'Select_full_join'};
581 $mycalc{'joins_without_indexes_per_day'} = int($mycalc{'joins_without_indexes'} / ($mystat{'Uptime'}/86400));
582
583 # Temporary tables
584 if ($mystat{'Created_tmp_tables'} > 0) {
585 if ($mystat{'Created_tmp_disk_tables'} > 0) {
586 $mycalc{'pct_temp_disk'} = int(($mystat{'Created_tmp_disk_tables'} / ($mystat{'Created_tmp_tables'} + $mystat{'Created_tmp_disk_tables'})) * 100);
587 } else {
588 $mycalc{'pct_temp_disk'} = 0;
589 }
590 }
591
592 # Table cache
593 if ($mystat{'Opened_tables'} > 0) {
594 $mycalc{'table_cache_hit_rate'} = int($mystat{'Open_tables'}*100/$mystat{'Opened_tables'});
595 } else {
596 $mycalc{'table_cache_hit_rate'} = 100;
597 }
598
599 # Open files
600 if ($myvar{'open_files_limit'} > 0) {
601 $mycalc{'pct_files_open'} = int($mystat{'Open_files'}*100/$myvar{'open_files_limit'});
602 }
603
604 # Table locks
605 if ($mystat{'Table_locks_immediate'} > 0) {
606 if ($mystat{'Table_locks_waited'} == 0) {
607 $mycalc{'pct_table_locks_immediate'} = 100;
608 } else {
609 $mycalc{'pct_table_locks_immediate'} = int($mystat{'Table_locks_immediate'}*100/($mystat{'Table_locks_waited'} + $mystat{'Table_locks_immediate'}));
610 }
611 }
612
613 # Thread cache
614 $mycalc{'thread_cache_hit_rate'} = int(100 - (($mystat{'Threads_created'} / $mystat{'Connections'}) * 100));
615
616 # Other
617 if ($mystat{'Connections'} > 0) {
618 $mycalc{'pct_aborted_connections'} = int(($mystat{'Aborted_connects'}/$mystat{'Connections'}) * 100);
619 }
620 if ($mystat{'Questions'} > 0) {
621 $mycalc{'total_reads'} = $mystat{'Com_select'};
622 $mycalc{'total_writes'} = $mystat{'Com_delete'} + $mystat{'Com_insert'} + $mystat{'Com_update'} + $mystat{'Com_replace'};
623 if ($mycalc{'total_reads'} == 0) {
624 $mycalc{'pct_reads'} = 0;
625 $mycalc{'pct_writes'} = 100;
626 } else {
627 $mycalc{'pct_reads'} = int(($mycalc{'total_reads'}/($mycalc{'total_reads'}+$mycalc{'total_writes'})) * 100);
628 $mycalc{'pct_writes'} = 100-$mycalc{'pct_reads'};
629 }
630 }
631
632 # InnoDB
633 if ($myvar{'have_innodb'} eq "YES") {
634 $mycalc{'innodb_log_size_pct'} = ($myvar{'innodb_log_file_size'} * 100 / $myvar{'innodb_buffer_pool_size'});
635 }
636 }
637
638 sub mysql_stats {
639 print "\n-------- Performance Metrics -------------------------------------------------\n";
640 # Show uptime, queries per second, connections, traffic stats
641 my $qps;
642 if ($mystat{'Uptime'} > 0) { $qps = sprintf("%.3f",$mystat{'Questions'}/$mystat{'Uptime'}); }
643 if ($mystat{'Uptime'} < 86400) { push(@generalrec,"MySQL started within last 24 hours - recommendations may be inaccurate"); }
644 infoprint "Up for: ".pretty_uptime($mystat{'Uptime'})." (".hr_num($mystat{'Questions'}).
645 " q [".hr_num($qps)." qps], ".hr_num($mystat{'Connections'})." conn,".
646 " TX: ".hr_num($mystat{'Bytes_sent'}).", RX: ".hr_num($mystat{'Bytes_received'}).")\n";
647 infoprint "Reads / Writes: ".$mycalc{'pct_reads'}."% / ".$mycalc{'pct_writes'}."%\n";
648
649 # Memory usage
650 infoprint "Total buffers: ".hr_bytes($mycalc{'server_buffers'})." global + ".hr_bytes($mycalc{'per_thread_buffers'})." per thread ($myvar{'max_connections'} max threads)\n";
651 if ($mycalc{'total_possible_used_memory'} > 2*1024*1024*1024 && $arch eq 32) {
652 badprint "Allocating > 2GB RAM on 32-bit systems can cause system instability\n";
653 badprint "Maximum possible memory usage: ".hr_bytes($mycalc{'total_possible_used_memory'})." ($mycalc{'pct_physical_memory'}% of installed RAM)\n";
654 } elsif ($mycalc{'pct_physical_memory'} > 85) {
655 badprint "Maximum possible memory usage: ".hr_bytes($mycalc{'total_possible_used_memory'})." ($mycalc{'pct_physical_memory'}% of installed RAM)\n";
656 push(@generalrec,"Reduce your overall MySQL memory footprint for system stability");
657 } else {
658 goodprint "Maximum possible memory usage: ".hr_bytes($mycalc{'total_possible_used_memory'})." ($mycalc{'pct_physical_memory'}% of installed RAM)\n";
659 }
660
661 # Slow queries
662 if ($mycalc{'pct_slow_queries'} > 5) {
663 badprint "Slow queries: $mycalc{'pct_slow_queries'}% (".hr_num($mystat{'Slow_queries'})."/".hr_num($mystat{'Questions'}).")\n";
664 } else {
665 goodprint "Slow queries: $mycalc{'pct_slow_queries'}% (".hr_num($mystat{'Slow_queries'})."/".hr_num($mystat{'Questions'}).")\n";
666 }
667 if ($myvar{'long_query_time'} > 10) { push(@adjvars,"long_query_time (<= 10)"); }
668 if (defined($myvar{'log_slow_queries'})) {
669 if ($myvar{'log_slow_queries'} eq "OFF") { push(@generalrec,"Enable the slow query log to troubleshoot bad queries"); }
670 }
671
672 # Connections
673 if ($mycalc{'pct_connections_used'} > 85) {
674 badprint "Highest connection usage: $mycalc{'pct_connections_used'}% ($mystat{'Max_used_connections'}/$myvar{'max_connections'})\n";
675 push(@adjvars,"max_connections (> ".$myvar{'max_connections'}.")");
676 push(@adjvars,"wait_timeout (< ".$myvar{'wait_timeout'}.")","interactive_timeout (< ".$myvar{'interactive_timeout'}.")");
677 push(@generalrec,"Reduce or eliminate persistent connections to reduce connection usage")
678 } else {
679 goodprint "Highest usage of available connections: $mycalc{'pct_connections_used'}% ($mystat{'Max_used_connections'}/$myvar{'max_connections'})\n";
680 }
681
682 # Key buffer
fff47e9 @major Fixed a Solaris awk bug, found a more reliable way to get the home direc...
authored
683 if (!defined($mycalc{'total_myisam_indexes'}) and $doremote == 1) {
c8c2dd9 @major Bumped version to 0.9.9
authored
684 push(@generalrec,"Unable to calculate MyISAM indexes on remote MySQL server < 5.0.0");
685 } elsif ($mycalc{'total_myisam_indexes'} =~ /^fail$/) {
686 badprint "Cannot calculate MyISAM index size - re-run script as root user\n";
687 } elsif ($mycalc{'total_myisam_indexes'} == "0") {
688 badprint "None of your MyISAM tables are indexed - add indexes immediately\n";
689 } else {
690 if ($myvar{'key_buffer_size'} < $mycalc{'total_myisam_indexes'} && $mycalc{'pct_keys_from_mem'} < 95) {
691 badprint "Key buffer size / total MyISAM indexes: ".hr_bytes($myvar{'key_buffer_size'})."/".hr_bytes($mycalc{'total_myisam_indexes'})."\n";
692 push(@adjvars,"key_buffer_size (> ".hr_bytes($mycalc{'total_myisam_indexes'}).")");
693 } else {
694 goodprint "Key buffer size / total MyISAM indexes: ".hr_bytes($myvar{'key_buffer_size'})."/".hr_bytes($mycalc{'total_myisam_indexes'})."\n";
695 }
696 if ($mystat{'Key_read_requests'} > 0) {
697 if ($mycalc{'pct_keys_from_mem'} < 95) {
698 badprint "Key buffer hit rate: $mycalc{'pct_keys_from_mem'}% (".hr_num($mystat{'Key_read_requests'})." cached / ".hr_num($mystat{'Key_reads'})." reads)\n";
699 } else {
700 goodprint "Key buffer hit rate: $mycalc{'pct_keys_from_mem'}% (".hr_num($mystat{'Key_read_requests'})." cached / ".hr_num($mystat{'Key_reads'})." reads)\n";
701 }
702 } else {
703 # No queries have run that would use keys
704 }
705 }
706
707 # Query cache
708 if ($mysqlvermajor < 4) {
709 # MySQL versions < 4.01 don't support query caching
710 push(@generalrec,"Upgrade MySQL to version 4+ to utilize query caching");
711 } elsif ($myvar{'query_cache_size'} < 1) {
712 badprint "Query cache is disabled\n";
713 push(@adjvars,"query_cache_size (>= 8M)");
714 } elsif ($mystat{'Com_select'} == 0) {
715 badprint "Query cache cannot be analyzed - no SELECT statements executed\n";
716 } else {
717 if ($mycalc{'query_cache_efficiency'} < 20) {
718 badprint "Query cache efficiency: $mycalc{'query_cache_efficiency'}% (".hr_num($mystat{'Qcache_hits'})." cached / ".hr_num($mystat{'Qcache_hits'}+$mystat{'Com_select'})." selects)\n";
719 push(@adjvars,"query_cache_limit (> ".hr_bytes_rnd($myvar{'query_cache_limit'}).", or use smaller result sets)");
720 } else {
721 goodprint "Query cache efficiency: $mycalc{'query_cache_efficiency'}% (".hr_num($mystat{'Qcache_hits'})." cached / ".hr_num($mystat{'Qcache_hits'}+$mystat{'Com_select'})." selects)\n";
722 }
723 if ($mycalc{'query_cache_prunes_per_day'} > 98) {
724 badprint "Query cache prunes per day: $mycalc{'query_cache_prunes_per_day'}\n";
c4bb3c0 @major A warning is now provided if if the query_cache_size goes over 128M. (Th...
authored
725 if ($myvar{'query_cache_size'} > 128*1024*1024) {
726 push(@generalrec,"Increasing the query_cache size over 128M may reduce performance");
727 push(@adjvars,"query_cache_size (> ".hr_bytes_rnd($myvar{'query_cache_size'}).") [see warning above]");
728 } else {
729 push(@adjvars,"query_cache_size (> ".hr_bytes_rnd($myvar{'query_cache_size'}).")");
730 }
c8c2dd9 @major Bumped version to 0.9.9
authored
731 } else {
732 goodprint "Query cache prunes per day: $mycalc{'query_cache_prunes_per_day'}\n";
733 }
734 }
735
736 # Sorting
737 if ($mycalc{'total_sorts'} == 0) {
738 # For the sake of space, we will be quiet here
739 # No sorts have run yet
740 } elsif ($mycalc{'pct_temp_sort_table'} > 10) {
741 badprint "Sorts requiring temporary tables: $mycalc{'pct_temp_sort_table'}% (".hr_num($mystat{'Sort_merge_passes'})." temp sorts / ".hr_num($mycalc{'total_sorts'})." sorts)\n";
742 push(@adjvars,"sort_buffer_size (> ".hr_bytes_rnd($myvar{'sort_buffer_size'}).")");
743 push(@adjvars,"read_rnd_buffer_size (> ".hr_bytes_rnd($myvar{'read_rnd_buffer_size'}).")");
744 } else {
745 goodprint "Sorts requiring temporary tables: $mycalc{'pct_temp_sort_table'}% (".hr_num($mystat{'Sort_merge_passes'})." temp sorts / ".hr_num($mycalc{'total_sorts'})." sorts)\n";
746 }
747
748 # Joins
749 if ($mycalc{'joins_without_indexes_per_day'} > 250) {
750 badprint "Joins performed without indexes: $mycalc{'joins_without_indexes'}\n";
751 push(@adjvars,"join_buffer_size (> ".hr_bytes($myvar{'join_buffer_size'}).", or always use indexes with joins)");
752 push(@generalrec,"Adjust your join queries to always utilize indexes");
753 } else {
754 # For the sake of space, we will be quiet here
755 # No joins have run without indexes
756 }
757
758 # Temporary tables
759 if ($mystat{'Created_tmp_tables'} > 0) {
760 if ($mycalc{'pct_temp_disk'} > 25 && $mycalc{'max_tmp_table_size'} < 256*1024*1024) {
761 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";
762 push(@adjvars,"tmp_table_size (> ".hr_bytes_rnd($myvar{'tmp_table_size'}).")");
763 push(@adjvars,"max_heap_table_size (> ".hr_bytes_rnd($myvar{'max_heap_table_size'}).")");
764 push(@generalrec,"When making adjustments, make tmp_table_size/max_heap_table_size equal");
765 push(@generalrec,"Reduce your SELECT DISTINCT queries without LIMIT clauses");
766 } elsif ($mycalc{'pct_temp_disk'} > 25 && $mycalc{'max_tmp_table_size'} >= 256) {
767 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";
768 push(@generalrec,"Temporary table size is already large - reduce result set size");
769 push(@generalrec,"Reduce your SELECT DISTINCT queries without LIMIT clauses");
770 } else {
771 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";
772 }
773 } else {
774 # For the sake of space, we will be quiet here
775 # No temporary tables have been created
776 }
777
778 # Thread cache
779 if ($myvar{'thread_cache_size'} eq 0) {
780 badprint "Thread cache is disabled\n";
781 push(@generalrec,"Set thread_cache_size to 4 as a starting value");
782 push(@adjvars,"thread_cache_size (start at 4)");
783 } else {
784 if ($mycalc{'thread_cache_hit_rate'} <= 50) {
785 badprint "Thread cache hit rate: $mycalc{'thread_cache_hit_rate'}% (".hr_num($mystat{'Threads_created'})." created / ".hr_num($mystat{'Connections'})." connections)\n";
786 push(@adjvars,"thread_cache_size (> $myvar{'thread_cache_size'})");
787 } else {
788 goodprint "Thread cache hit rate: $mycalc{'thread_cache_hit_rate'}% (".hr_num($mystat{'Threads_created'})." created / ".hr_num($mystat{'Connections'})." connections)\n";
789 }
790 }
791
792 # Table cache
793 if ($mystat{'Open_tables'} > 0) {
794 if ($mycalc{'table_cache_hit_rate'} < 20) {
795 badprint "Table cache hit rate: $mycalc{'table_cache_hit_rate'}% (".hr_num($mystat{'Open_tables'})." open / ".hr_num($mystat{'Opened_tables'})." opened)\n";
c0ab5bc @major Version bump to 1.0.0-rc1
authored
796 if ($mysqlvermajor eq 6 || ($mysqlvermajor eq 5 && $mysqlverminor ge 1)) {
c8c2dd9 @major Bumped version to 0.9.9
authored
797 push(@adjvars,"table_cache (> ".$myvar{'table_open_cache'}.")");
798 } else {
799 push(@adjvars,"table_cache (> ".$myvar{'table_cache'}.")");
800 }
801 push(@generalrec,"Increase table_cache gradually to avoid file descriptor limits");
802 } else {
803 goodprint "Table cache hit rate: $mycalc{'table_cache_hit_rate'}% (".hr_num($mystat{'Open_tables'})." open / ".hr_num($mystat{'Opened_tables'})." opened)\n";
804 }
805 }
806
807 # Open files
808 if (defined $mycalc{'pct_files_open'}) {
809 if ($mycalc{'pct_files_open'} > 85) {
810 badprint "Open file limit used: $mycalc{'pct_files_open'}% (".hr_num($mystat{'Open_files'})."/".hr_num($myvar{'open_files_limit'}).")\n";
811 push(@adjvars,"open_files_limit (> ".$myvar{'open_files_limit'}.")");
812 } else {
813 goodprint "Open file limit used: $mycalc{'pct_files_open'}% (".hr_num($mystat{'Open_files'})."/".hr_num($myvar{'open_files_limit'}).")\n";
814 }
815 }
816
817 # Table locks
818 if (defined $mycalc{'pct_table_locks_immediate'}) {
819 if ($mycalc{'pct_table_locks_immediate'} < 95) {
820 badprint "Table locks acquired immediately: $mycalc{'pct_table_locks_immediate'}%\n";
821 push(@generalrec,"Optimize queries and/or use InnoDB to reduce lock wait");
822 } else {
823 goodprint "Table locks acquired immediately: $mycalc{'pct_table_locks_immediate'}% (".hr_num($mystat{'Table_locks_immediate'})." immediate / ".hr_num($mystat{'Table_locks_waited'}+$mystat{'Table_locks_immediate'})." locks)\n";
824 }
825 }
826
827 # Performance options
828 if ($mysqlvermajor == 3 || ($mysqlvermajor == 4 && $mysqlverminor == 0)) {
829 push(@generalrec,"Upgrade to MySQL 4.1+ to use concurrent MyISAM inserts");
830 } elsif ($myvar{'concurrent_insert'} eq "OFF") {
831 push(@generalrec,"Enable concurrent_insert by setting it to 'ON'");
832 } elsif ($myvar{'concurrent_insert'} eq 0) {
833 push(@generalrec,"Enable concurrent_insert by setting it to 1");
834 }
835 if ($mycalc{'pct_aborted_connections'} > 5) {
836 badprint "Connections aborted: ".$mycalc{'pct_aborted_connections'}."%\n";
837 push(@generalrec,"Your applications are not closing MySQL connections properly");
838 }
839
840 # InnoDB
841 if (defined $myvar{'have_innodb'} && $myvar{'have_innodb'} eq "YES" && defined $enginestats{'InnoDB'}) {
842 if ($myvar{'innodb_buffer_pool_size'} > $enginestats{'InnoDB'}) {
843 goodprint "InnoDB data size / buffer pool: ".hr_bytes($enginestats{'InnoDB'})."/".hr_bytes($myvar{'innodb_buffer_pool_size'})."\n";
844 } else {
845 badprint "InnoDB data size / buffer pool: ".hr_bytes($enginestats{'InnoDB'})."/".hr_bytes($myvar{'innodb_buffer_pool_size'})."\n";
846 push(@adjvars,"innodb_buffer_pool_size (>= ".hr_bytes_rnd($enginestats{'InnoDB'}).")");
847 }
848 }
849 }
850
851 # Take the two recommendation arrays and display them at the end of the output
852 sub make_recommendations {
853 print "\n-------- Recommendations -----------------------------------------------------\n";
854 if (@generalrec > 0) {
855 print "General recommendations:\n";
856 foreach (@generalrec) { print " ".$_."\n"; }
857 }
858 if (@adjvars > 0) {
859 print "Variables to adjust:\n";
c0ab5bc @major Version bump to 1.0.0-rc1
authored
860 if ($mycalc{'pct_physical_memory'} > 90) {
861 print " *** MySQL's maximum memory usage is dangerously high ***\n".
862 " *** Add RAM before increasing MySQL buffer variables ***\n";
c8c2dd9 @major Bumped version to 0.9.9
authored
863 }
864 foreach (@adjvars) { print " ".$_."\n"; }
865 }
866 if (@generalrec == 0 && @adjvars ==0) {
867 print "No additional performance recommendations are available.\n"
868 }
869 print "\n";
870 }
871
872 # ---------------------------------------------------------------------------
873 # BEGIN 'MAIN'
874 # ---------------------------------------------------------------------------
875 print "\n >> MySQLTuner $tunerversion - Major Hayden <major\@mhtx.net>\n".
876 " >> Bug reports, feature requests, and downloads at http://mysqltuner.com/\n".
877 " >> Run with '--help' for additional options and output filtering\n";
878 mysql_setup; # Gotta login first
879 os_setup; # Set up some OS variables
880 get_all_vars; # Toss variables/status into hashes
881 validate_tuner_version; # Check current MySQLTuner version
882 validate_mysql_version; # Check current MySQL version
883 check_architecture; # Suggest 64-bit upgrade
884 check_storage_engines; # Show enabled storage engines
885 calculations; # Calculate everything we need
886 mysql_stats; # Print the server stats
887 make_recommendations; # Make recommendations based on stats
888 # ---------------------------------------------------------------------------
889 # END 'MAIN'
890 # ---------------------------------------------------------------------------
Something went wrong with that request. Please try again.