Skip to content

HTTPS clone URL

Subversion checkout URL

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