| 80 | | " --skipsize Don't enumerate tables and their types/sizes\n". |
|---|
| 81 | | " (Recommended for servers with many tables)\n". |
|---|
| 82 | | " --skipversion Don't check for updates to MySQLTuner\n\n". |
|---|
| | 95 | " --skipsize Don't enumerate tables and their types/sizes\n". |
|---|
| | 96 | " (Recommended for servers with many tables)\n". |
|---|
| | 97 | " --skipversion Don't check for updates to MySQLTuner\n". |
|---|
| | 98 | " --forcemem i Amount of RAM installed in megabytes\n". |
|---|
| | 99 | " --forceswap i Amount of swap memory configured in megabytes\n". |
|---|
| | 100 | "\n". |
|---|
| 170 | | $duflags = ''; |
|---|
| 171 | | if ($os =~ /Linux/) { |
|---|
| 172 | | $physical_memory = `free -b | grep Mem | awk '{print \$2}'`; |
|---|
| 173 | | $swap_memory = `free -b | grep Swap | awk '{print \$2}'`; |
|---|
| 174 | | $duflags = '-b'; |
|---|
| 175 | | } elsif ($os =~ /Darwin/) { |
|---|
| 176 | | $physical_memory = `sysctl -n hw.memsize`; |
|---|
| 177 | | $swap_memory = `sysctl -n vm.swapusage | awk '{print \$3}' | sed 's/\..*\$//'`; |
|---|
| 178 | | } elsif ($os =~ /NetBSD/) { |
|---|
| 179 | | $physical_memory = `sysctl -n hw.physmem`; |
|---|
| 180 | | $swap_memory = `swapctl -l | grep '^/' | awk '{ s+= \$2 } END { print s }'`; |
|---|
| 181 | | } elsif ($os =~ /BSD/) { |
|---|
| 182 | | $physical_memory = `sysctl -n hw.realmem`; |
|---|
| 183 | | $swap_memory = `swapinfo | grep '^/' | awk '{ s+= \$2 } END { print s }'`; |
|---|
| | 192 | $duflags = ($os =~ /Linux/) ? '-b' : ''; |
|---|
| | 193 | if ($opt{'forcemem'} > 0) { |
|---|
| | 194 | $physical_memory = $opt{'forcemem'} * 1048576; |
|---|
| | 195 | infoprint "Assuming $opt{'forcemem'} MB of physical memory\n"; |
|---|
| | 196 | if ($opt{'forceswap'} > 0) { |
|---|
| | 197 | $swap_memory = $opt{'forceswap'} * 1048576; |
|---|
| | 198 | infoprint "Assuming $opt{'forceswap'} MB of swap space\n"; |
|---|
| | 199 | } else { |
|---|
| | 200 | $swap_memory = 0; |
|---|
| | 201 | badprint "Assuming 0 MB of swap space (use --forceswap to specify)\n"; |
|---|
| | 202 | } |
|---|
| | 203 | } else { |
|---|
| | 204 | if ($os =~ /Linux/) { |
|---|
| | 205 | $physical_memory = `free -b | grep Mem | awk '{print \$2}'` or memerror; |
|---|
| | 206 | $swap_memory = `free -b | grep Swap | awk '{print \$2}'` or memerror; |
|---|
| | 207 | } elsif ($os =~ /Darwin/) { |
|---|
| | 208 | $physical_memory = `sysctl -n hw.memsize` or memerror; |
|---|
| | 209 | $swap_memory = `sysctl -n vm.swapusage | awk '{print \$3}' | sed 's/\..*\$//'` or memerror; |
|---|
| | 210 | } elsif ($os =~ /NetBSD/) { |
|---|
| | 211 | $physical_memory = `sysctl -n hw.physmem` or memerror; |
|---|
| | 212 | $swap_memory = `swapctl -l | grep '^/' | awk '{ s+= \$2 } END { print s }'` or memerror; |
|---|
| | 213 | } elsif ($os =~ /BSD/) { |
|---|
| | 214 | $physical_memory = `sysctl -n hw.realmem`; |
|---|
| | 215 | $swap_memory = `swapinfo | grep '^/' | awk '{ s+= \$2 } END { print s }'`; |
|---|
| | 216 | } |
|---|
| 197 | | if ( -r "/etc/psa/.psa.shadow" ) { |
|---|
| | 232 | # Are we being asked to connect to a remote server? |
|---|
| | 233 | if ($opt{host} ne 0) { |
|---|
| | 234 | chomp($opt{host}); |
|---|
| | 235 | $opt{port} = ($opt{port} eq 0)? 3306 : $opt{port} ; |
|---|
| | 236 | # If we're doing a remote connection, but forcemem wasn't specified, we need to exit |
|---|
| | 237 | if ($opt{'forcemem'} eq 0) { |
|---|
| | 238 | badprint "The --forcemem option is required for remote connections\n"; |
|---|
| | 239 | exit; |
|---|
| | 240 | } |
|---|
| | 241 | infoprint "Performing tests on $opt{host}:$opt{port}\n"; |
|---|
| | 242 | $remotestring = " -h $opt{host} -P $opt{port}"; |
|---|
| | 243 | $doremote = 1; |
|---|
| | 244 | } |
|---|
| | 245 | # Did we already get a username and password passed on the command line? |
|---|
| | 246 | if ($opt{user} ne 0 and $opt{pass} ne 0) { |
|---|
| | 247 | $mysqllogin = "-u $opt{user} -p'$opt{pass}'".$remotestring; |
|---|
| | 248 | my $loginstatus = `mysqladmin ping $mysqllogin 2>&1`; |
|---|
| | 249 | if ($loginstatus =~ /mysqld is alive/) { |
|---|
| | 250 | goodprint "Logged in using credentials passed on the command line\n"; |
|---|
| | 251 | return 1; |
|---|
| | 252 | } else { |
|---|
| | 253 | badprint "Attempted to use login credentials, but they were invalid\n"; |
|---|
| | 254 | exit 0; |
|---|
| | 255 | } |
|---|
| | 256 | } |
|---|
| | 257 | if ( -r "/etc/psa/.psa.shadow" and $doremote == 0 ) { |
|---|
| 456 | | $mycalc{'total_myisam_indexes'} = `find $myvar{'datadir'} -name '*.MYI' 2>&1 | xargs du -L $duflags '{}' 2>&1 | awk '{ s += \$1 } END { print s }'`; |
|---|
| 457 | | if ($mycalc{'total_myisam_indexes'} =~ /^0\n$/) { $mycalc{'total_myisam_indexes'} = "fail"; } |
|---|
| 458 | | chomp($mycalc{'total_myisam_indexes'}); |
|---|
| | 518 | if ($doremote eq 0) { |
|---|
| | 519 | $mycalc{'total_myisam_indexes'} = `find $myvar{'datadir'} -name '*.MYI' 2>&1 | xargs du -L $duflags '{}' 2>&1 | awk '{ s += \$1 } END { print s }'`; |
|---|
| | 520 | } elsif ($doremote eq 1 and $mysqlvermajor >= 5) { |
|---|
| | 521 | $mycalc{'total_myisam_indexes'} = `mysql $mysqllogin -Bse "SELECT SUM(INDEX_LENGTH) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema');"`; |
|---|
| | 522 | } |
|---|
| | 523 | if (defined $mycalc{'total_myisam_indexes'} and $mycalc{'total_myisam_indexes'} =~ /^0\n$/) { |
|---|
| | 524 | $mycalc{'total_myisam_indexes'} = "fail"; |
|---|
| | 525 | } elsif (defined $mycalc{'total_myisam_indexes'}) { |
|---|
| | 526 | chomp($mycalc{'total_myisam_indexes'}); |
|---|
| | 527 | } |
|---|