Merge pull request #2 from DutchProgrammer/v1.6.9

V1.6.9
This commit is contained in:
Danny 2016-03-24 22:50:33 +01:00
commit 97c0aaf796

View file

@ -1,7 +1,7 @@
#!/usr/bin/env perl #!/usr/bin/env perl
# mysqltuner.pl - Version 1.6.8 # mysqltuner.pl - Version 1.6.9
# High Performance MySQL Tuning Script # High Performance MySQL Tuning Script
# Copyright (C) 2006-2015 Major Hayden - major@mhtx.net # Copyright (C) 2006-2016 Major Hayden - major@mhtx.net
# #
# For the latest updates, please visit http://mysqltuner.com/ # For the latest updates, please visit http://mysqltuner.com/
# Git repository available at http://github.com/major/MySQLTuner-perl # Git repository available at http://github.com/major/MySQLTuner-perl
@ -51,102 +51,114 @@ use Data::Dumper;
$Data::Dumper::Pair = " : "; $Data::Dumper::Pair = " : ";
# Set up a few variables for use in the script # Set up a few variables for use in the script
my $tunerversion = "1.6.8"; my $tunerversion = "1.6.9";
my ( @adjvars, @generalrec ); my ( @adjvars, @generalrec );
# Set defaults # Set defaults
my %opt = ( my %opt = (
"silent" => 0, "silent" => 0,
"nobad" => 0, "nobad" => 0,
"nogood" => 0, "nogood" => 0,
"noinfo" => 0, "noinfo" => 0,
"debug" => 0, "debug" => 0,
"nocolor" => 0, "nocolor" => 0,
"forcemem" => 0, "forcemem" => 0,
"forceswap" => 0, "forceswap" => 0,
"host" => 0, "host" => 0,
"socket" => 0, "socket" => 0,
"port" => 0, "port" => 0,
"user" => 0, "user" => 0,
"pass" => 0, "pass" => 0,
"skipsize" => 0, "skipsize" => 0,
"checkversion" => 0, "checkversion" => 0,
"buffers" => 0, "updateversion" => 0,
"passwordfile" => 0, "buffers" => 0,
"bannedports" => '', "passwordfile" => 0,
"maxportallowed"=> 0, "bannedports" => '',
"outputfile" => 0, "maxportallowed" => 0,
"dbstat" => 0, "outputfile" => 0,
"idxstat" => 0, "dbstat" => 0,
"skippassword" => 0, "idxstat" => 0,
"noask" => 0, "skippassword" => 0,
"template" => 0, "noask" => 0,
"json" => 0, "template" => 0,
"reportfile" => 0 "json" => 0,
"prettyjson" => 0,
"reportfile" => 0,
"verbose" => 0
); );
# Gather the options from the command line # Gather the options from the command line
GetOptions( my $getOptionsCheck = GetOptions(
\%opt, 'nobad', 'nogood', 'noinfo', \%opt, 'nobad', 'nogood', 'noinfo',
'debug', 'nocolor', 'forcemem=i', 'forceswap=i', 'debug', 'nocolor', 'forcemem=i', 'forceswap=i',
'host=s', 'socket=s', 'port=i', 'user=s', 'host=s', 'socket=s', 'port=i', 'user=s',
'pass=s', 'skipsize', 'checkversion', 'mysqladmin=s', 'pass=s', 'skipsize', 'checkversion', 'mysqladmin=s',
'mysqlcmd=s', 'help', 'buffers', 'skippassword', 'mysqlcmd=s', 'help', 'buffers', 'skippassword',
'passwordfile=s', 'outputfile=s', 'silent', 'dbstat', 'json', 'passwordfile=s', 'outputfile=s', 'silent', 'dbstat',
'idxstat', 'noask', 'template=s', 'reportfile=s', 'cvefile=s', 'json', 'prettyjson', 'idxstat', 'noask',
'bannedports=s','maxportallowed=s', 'template=s', 'reportfile=s', 'cvefile=s', 'bannedports=s',
'updateversion', 'maxportallowed=s', 'verbose'
); );
#If params are incorrect return help
if ($getOptionsCheck ne 1) {
usage();
}
if ( defined $opt{'help'} && $opt{'help'} == 1 ) { usage(); } if ( defined $opt{'help'} && $opt{'help'} == 1 ) { usage(); }
sub usage { sub usage {
# Shown with --help option passed # Shown with --help option passed
print " MySQLTuner $tunerversion - MySQL High Performance Tuning Script\n" print " MySQLTuner $tunerversion - MySQL High Performance Tuning Script\n"
. " Bug reports, feature requests, and downloads at http://mysqltuner.com/\n" . " Bug reports, feature requests, and downloads at http://mysqltuner.com/\n"
. " Maintained by Major Hayden (major\@mhtx.net) - Licensed under GPL\n" . " Maintained by Major Hayden (major\@mhtx.net) - Licensed under GPL\n"
. "\n" . "\n"
. " Important Usage Guidelines:\n" . " Important Usage Guidelines:\n"
. " To run the script with the default options, run the script without arguments\n" . " To run the script with the default options, run the script without arguments\n"
. " Allow MySQL server to run for at least 24-48 hours before trusting suggestions\n" . " Allow MySQL server to run for at least 24-48 hours before trusting suggestions\n"
. " Some routines may require root level privileges (script will provide warnings)\n" . " Some routines may require root level privileges (script will provide warnings)\n"
. " You must provide the remote server's total memory when connecting to other servers\n" . " You must provide the remote server's total memory when connecting to other servers\n"
. "\n" . "\n"
. " Connection and Authentication\n" . " Connection and Authentication\n"
. " --host <hostname> Connect to a remote host to perform tests (default: localhost)\n" . " --host <hostname> Connect to a remote host to perform tests (default: localhost)\n"
. " --socket <socket> Use a different socket for a local connection\n" . " --socket <socket> Use a different socket for a local connection\n"
. " --port <port> Port to use for connection (default: 3306)\n" . " --port <port> Port to use for connection (default: 3306)\n"
. " --user <username> Username to use for authentication\n" . " --user <username> Username to use for authentication\n"
. " --pass <password> Password to use for authentication\n" . " --pass <password> Password to use for authentication\n"
. " --mysqladmin <path> Path to a custom mysqladmin executable\n" . " --mysqladmin <path> Path to a custom mysqladmin executable\n"
. " --mysqlcmd <path> Path to a custom mysql executable\n" . "\n" . " --mysqlcmd <path> Path to a custom mysql executable\n" . "\n"
. " --noask Dont ask password if needed\n" . "\n" . " --noask Dont ask password if needed\n" . "\n"
. " Performance and Reporting Options\n" . " Performance and Reporting Options\n"
. " --skipsize Don't enumerate tables and their types/sizes (default: on)\n" . " --skipsize Don't enumerate tables and their types/sizes (default: on)\n"
. " (Recommended for servers with many tables)\n" . " (Recommended for servers with many tables)\n"
. " --skippassword Don't perform checks on user passwords(default: off)\n" . " --skippassword Don't perform checks on user passwords(default: off)\n"
. " --checkversion Check for updates to MySQLTuner (default: don't check)\n" . " --checkversion Check for updates to MySQLTuner (default: don't check)\n"
. " --forcemem <size> Amount of RAM installed in megabytes\n" . " --updateversion Check for updates to MySQLTuner and update when newer version is available (default: don't check)\n"
. " --forceswap <size> Amount of swap memory configured in megabytes\n" . " --forcemem <size> Amount of RAM installed in megabytes\n"
. " --passwordfile <path>Path to a password file list(one password by line)\n" . " --forceswap <size> Amount of swap memory configured in megabytes\n"
. " Output Options:\n" . " --passwordfile <path>Path to a password file list(one password by line)\n"
. " --silent Don't output anything on screen\n" . " Output Options:\n"
. " --nogood Remove OK responses\n" . " --silent Don't output anything on screen\n"
. " --nobad Remove negative/suggestion responses\n" . " --nogood Remove OK responses\n"
. " --noinfo Remove informational responses\n" . " --nobad Remove negative/suggestion responses\n"
. " --debug Print debug information\n" . " --noinfo Remove informational responses\n"
. " --dbstat Print database information\n" . " --debug Print debug information\n"
. " --idxstat Print index information\n" . " --dbstat Print database information\n"
. " --bannedports Ports banned separated by comma(,)\n" . " --idxstat Print index information\n"
. " --maxportallowed Number of ports opened allowed on this hosts\n" . " --bannedports Ports banned separated by comma(,)\n"
. " --cvefile CVE File for vulnerability checks\n" . " --maxportallowed Number of ports opened allowed on this hosts\n"
. " --nocolor Don't print output in color\n" . " --cvefile CVE File for vulnerability checks\n"
. " --json Print result as JSON string\n" . " --nocolor Don't print output in color\n"
. " --buffers Print global and per-thread buffer values\n" . " --json Print result as JSON string\n"
. " --outputfile <path> Path to a output txt file\n" . "\n" . " --prettyjson Print result as human readable JSON\n"
. " --reportfile <path> Path to a report txt file\n" . "\n" . " --buffers Print global and per-thread buffer values\n"
. " --template <path> Path to a template file\n" . "\n"; . " --outputfile <path> Path to a output txt file\n" . "\n"
exit 0; . " --reportfile <path> Path to a report txt file\n" . "\n"
. " --template <path> Path to a template file\n" . "\n"
. " --verbose Prints out all options (default: no verbose) \n" . "\n";
exit 0;
} }
my $devnull = File::Spec->devnull(); my $devnull = File::Spec->devnull();
@ -159,6 +171,15 @@ my $basic_password_files =
$basic_password_files = "/usr/share/mysqltuner/basic_passwords.txt" $basic_password_files = "/usr/share/mysqltuner/basic_passwords.txt"
unless -f "$basic_password_files"; unless -f "$basic_password_files";
# check if we need to enable verbose mode
if ($opt{verbose}) {
$opt{checkversion} = 1; #Check for updates to MySQLTuner
$opt{dbstat} = 1; #Print database information
$opt{idxstat} = 1; #Print index information
$opt{buffers} = 1; #Print global and per-thread buffer values
$opt{cvefile} = 'vulnerabilities.csv'; #CVE File for vulnerability checks
}
# for RPM distributions # for RPM distributions
$opt{cvefile} = "/usr/share/mysqltuner/vulnerabilities.csv" $opt{cvefile} = "/usr/share/mysqltuner/vulnerabilities.csv"
unless ( defined $opt{cvefile} and -f "$opt{cvefile}"); unless ( defined $opt{cvefile} and -f "$opt{cvefile}");
@ -189,7 +210,7 @@ my %result;
# Functions that handle the print styles # Functions that handle the print styles
sub prettyprint { sub prettyprint {
print $_[0] . "\n" unless $opt{'silent'}; print $_[0] . "\n" unless ($opt{'silent'} or $opt{'json'});
print $fh $_[0] . "\n" if defined($fh); print $fh $_[0] . "\n" if defined($fh);
} }
sub goodprint { prettyprint $good. " " . $_[0] unless ( $opt{nogood} == 1 ); } sub goodprint { prettyprint $good. " " . $_[0] unless ( $opt{nogood} == 1 ); }
@ -385,8 +406,8 @@ sub os_setup {
# Checks for updates to MySQLTuner # Checks for updates to MySQLTuner
sub validate_tuner_version { sub validate_tuner_version {
if ($opt{checkversion} eq 0) { if ($opt{'checkversion'} eq 0 and $opt{'updateversion'} eq 0) {
print "\n"; print "\n" unless ($opt{'silent'} or $opt{'json'});
infoprint "Skipped version check for MySQLTuner script"; infoprint "Skipped version check for MySQLTuner script";
return; return;
} }
@ -424,12 +445,80 @@ sub validate_tuner_version {
infoprint "Unable to check for the latest MySQLTuner version"; infoprint "Unable to check for the latest MySQLTuner version";
} }
# Checks for updates to MySQLTuner
sub update_tuner_version {
if ($opt{'updateversion'} eq 0) {
badprint "Skipped version update for MySQLTuner script";
print "\n" unless ($opt{'silent'} or $opt{'json'});
return;
}
#use Cwd;
my $update;
my $url = "https://raw.githubusercontent.com/major/MySQLTuner-perl/master/";
my @scripts = ("mysqltuner.pl", "basic_passwords.txt", "vulnerabilities.csv");
my $totalScripts = scalar(keys @scripts);
my $receivedScripts = 0;
my $httpcli =`which curl`;
foreach my $script (@scripts) {
chomp($httpcli);
if ( 1 != 1 and defined($httpcli) and -e "$httpcli" ) {
debugprint "$httpcli is available.";
debugprint "$httpcli --connect-timeout 5 -silent '$url$script' > $script";
$update = `$httpcli --connect-timeout 5 -silent '$url$script' > $script`;
chomp($update);
debugprint "$script updated: $update";
if ( -s $script eq 0) {
badprint "Couldn't update $script";
} else {
++$receivedScripts;
debugprint "$script updated: $update";
}
} else {
$httpcli=`which wget`;
chomp($httpcli);
if ( defined($httpcli) and -e "$httpcli" ) {
debugprint "$httpcli is available.";
debugprint "$httpcli -qe timestamping=off -T 5 -O $script '$url$script'";
$update = `$httpcli -qe timestamping=off -T 5 -O $script '$url$script'`;
chomp($update);
if ( -s $script eq 0) {
badprint "Couldn't update $script";
} else {
++$receivedScripts;
debugprint "$script updated: $update";
}
} else {
debugprint "curl and wget are not available.";
infoprint "Unable to check for the latest MySQLTuner version";
}
}
}
if ($receivedScripts eq $totalScripts) {
goodprint "Successfully updated MySQLTuner script";
} else {
badprint "Couldn't update MySQLTuner script";
}
exit 0;
}
sub compare_tuner_version { sub compare_tuner_version {
my $remoteversion=shift; my $remoteversion=shift;
debugprint "Remote data: $remoteversion"; debugprint "Remote data: $remoteversion";
#exit 0; #exit 0;
if ($remoteversion ne $tunerversion) { if ($remoteversion ne $tunerversion) {
badprint "There is a new version of MySQLTuner available ($remoteversion)"; badprint "There is a new version of MySQLTuner available ($remoteversion)";
update_tuner_version();
return; return;
} }
goodprint "You have the latest version of MySQLTuner($tunerversion)"; goodprint "You have the latest version of MySQLTuner($tunerversion)";
@ -709,14 +798,14 @@ sub select_array {
debugprint "PERFORM: $req "; debugprint "PERFORM: $req ";
my @result = `$mysqlcmd $mysqllogin -Bse "$req" 2>>/dev/null`; my @result = `$mysqlcmd $mysqllogin -Bse "$req" 2>>/dev/null`;
if ($? != 0) { if ($? != 0) {
badprint "failed to execute: $req"; badprint "failed to execute: $req";
badprint "FAIL Execute SQL / return code: $?"; badprint "FAIL Execute SQL / return code: $?";
debugprint "CMD : $mysqlcmd"; debugprint "CMD : $mysqlcmd";
debugprint "OPTIONS: $mysqllogin"; debugprint "OPTIONS: $mysqllogin";
debugprint `$mysqlcmd $mysqllogin -Bse "$req" 2>&1`; debugprint `$mysqlcmd $mysqllogin -Bse "$req" 2>&1`;
exit $?; exit $?;
} }
debugprint "select_array: return code : $?"; debugprint "select_array: return code : $?";
chomp(@result); chomp(@result);
return @result; return @result;
} }
@ -727,14 +816,14 @@ sub select_one {
debugprint "PERFORM: $req "; debugprint "PERFORM: $req ";
my $result = `$mysqlcmd $mysqllogin -Bse "$req" 2>>/dev/null`; my $result = `$mysqlcmd $mysqllogin -Bse "$req" 2>>/dev/null`;
if ($? != 0) { if ($? != 0) {
badprint "failed to execute: $req"; badprint "failed to execute: $req";
badprint "FAIL Execute SQL / return code: $?"; badprint "FAIL Execute SQL / return code: $?";
debugprint "CMD : $mysqlcmd"; debugprint "CMD : $mysqlcmd";
debugprint "OPTIONS: $mysqllogin"; debugprint "OPTIONS: $mysqllogin";
debugprint `$mysqlcmd $mysqllogin -Bse "$req" 2>&1`; debugprint `$mysqlcmd $mysqllogin -Bse "$req" 2>&1`;
exit $?; exit $?;
} }
debugprint "select_array: return code : $?"; debugprint "select_array: return code : $?";
chomp($result); chomp($result);
return $result; return $result;
} }
@ -887,9 +976,9 @@ sub cve_recommendations {
sub get_opened_ports { sub get_opened_ports {
my @opened_ports=`netstat -ltn`; my @opened_ports=`netstat -ltn`;
map { map {
s/.*:(\d+)\s.*$/$1/; s/.*:(\d+)\s.*$/$1/;
s/\D//g; s/\D//g;
} @opened_ports; } @opened_ports;
@opened_ports = sort {$a <=> $b} grep { !/^$/ } @opened_ports; @opened_ports = sort {$a <=> $b} grep { !/^$/ } @opened_ports;
debugprint Dumper \@opened_ports; debugprint Dumper \@opened_ports;
return @opened_ports; return @opened_ports;
@ -904,26 +993,26 @@ sub is_open_port {
} }
sub get_process_memory { sub get_process_memory {
my $pid=shift; my $pid=shift;
return 0 unless -f "/proc/$pid/status"; return 0 unless -f "/proc/$pid/status";
my @pdata= grep { /RSS:/ } get_file_contents "/proc/$pid/status"; my @pdata= grep { /RSS:/ } get_file_contents "/proc/$pid/status";
map { map {
s/.*RSS:\s*(\d+)\s*kB\s*$/$1*1024/ge s/.*RSS:\s*(\d+)\s*kB\s*$/$1*1024/ge
} @pdata; } @pdata;
return $pdata[0]; return $pdata[0];
} }
sub get_other_process_memory { sub get_other_process_memory {
my @procs=`ps -eo pid,cmd`; my @procs=`ps -eo pid,cmd`;
map { s/.*mysqld.*//; s/.*\[.*\].*//; s/^\s+$//g; s/.*PID.*CMD.*//; s/.*systemd.*//;} @procs; map { s/.*mysqld.*//; s/.*\[.*\].*//; s/^\s+$//g; s/.*PID.*CMD.*//; s/.*systemd.*//;} @procs;
map {s/\s*?(\d+)\s*.*/$1/g;} @procs; map {s/\s*?(\d+)\s*.*/$1/g;} @procs;
remove_cr @procs; remove_cr @procs;
@procs=remove_empty @procs; @procs=remove_empty @procs;
my $totalMemOther=0; my $totalMemOther=0;
map { map {
$totalMemOther+=get_process_memory($_); $totalMemOther+=get_process_memory($_);
} @procs; } @procs;
return $totalMemOther; return $totalMemOther;
} }
sub get_os_release { sub get_os_release {
@ -947,34 +1036,34 @@ sub system_recommendations {
infoprint "User process except mysqld used ". hr_bytes_rnd($omem) . " RAM."; infoprint "User process except mysqld used ". hr_bytes_rnd($omem) . " RAM.";
if ( (0.15*$physical_memory) < $omem) { if ( (0.15*$physical_memory) < $omem) {
badprint "Other user process except mysqld used more than 15% of total physical memory ". percentage($omem, $physical_memory). "% (".hr_bytes_rnd($omem). " / ".hr_bytes_rnd($physical_memory).")"; badprint "Other user process except mysqld used more than 15% of total physical memory ". percentage($omem, $physical_memory). "% (".hr_bytes_rnd($omem). " / ".hr_bytes_rnd($physical_memory).")";
push( @generalrec, "Consider stopping or dedicate server for additionnal process other than mysqld." ); push( @generalrec, "Consider stopping or dedicate server for additionnal process other than mysqld." );
push( @adjvars, "DON'T APPLY SETTINGS BECAUSE THERE IS TOO MANY PROCESSES RUNNING ON THIS SERVER. OOM KILL CAN OCCURS !" ); push( @adjvars, "DON'T APPLY SETTINGS BECAUSE THERE IS TOO MANY PROCESSES RUNNING ON THIS SERVER. OOM KILL CAN OCCURS !" );
} else { } else {
} }
#if ($omem > #if ($omem >
#exit 0; #exit 0;
if ($opt{'maxportallowed'} > 0) { if ($opt{'maxportallowed'} > 0) {
my @opened_ports=get_opened_ports; my @opened_ports=get_opened_ports;
infoprint "There is ". scalar @opened_ports. " listening port(s) on this server."; infoprint "There is ". scalar @opened_ports. " listening port(s) on this server.";
if (scalar(@opened_ports) > $opt{'maxportallowed'}) { if (scalar(@opened_ports) > $opt{'maxportallowed'}) {
badprint "There is too many listening ports: ". scalar(@opened_ports) " opened > ".$opt{'maxportallowed'}. "allowed."; badprint "There is too many listening ports: ". scalar(@opened_ports). " opened > ".$opt{'maxportallowed'}. "allowed.";
push( @generalrec, "Consider dedicating a server for your database installation with less services running on !" ); push( @generalrec, "Consider dedicating a server for your database installation with less services running on !" );
} else { } else {
goodprint "There is less than ".$opt{'maxportallowed'}." opened ports on this server."; goodprint "There is less than ".$opt{'maxportallowed'}." opened ports on this server.";
} }
} }
foreach my $banport (@banned_ports) { foreach my $banport (@banned_ports) {
if ( is_open_port($banport) ) { if ( is_open_port($banport) ) {
badprint "Banned port: $banport is opened.."; badprint "Banned port: $banport is opened..";
push( @generalrec, "Port $banport is opened. Consider stopping program handling this port." ); push( @generalrec, "Port $banport is opened. Consider stopping program handling this port." );
} else { } else {
goodprint "$banport is not opened."; goodprint "$banport is not opened.";
} }
} }
} }
@ -1330,7 +1419,7 @@ sub check_storage_engines {
$result{'Databases'}{'List'} = [@dblist]; $result{'Databases'}{'List'} = [@dblist];
infoprint "Status: $engines"; infoprint "Status: $engines";
if ( mysql_version_ge( 5, 1, 5 ) ) { if ( mysql_version_ge( 5, 1, 5 ) ) {
# MySQL 5 servers can have table sizes calculated quickly from information schema # MySQL 5 servers can have table sizes calculated quickly from information schema
my @templist = select_array my @templist = select_array
"SELECT ENGINE,SUM(DATA_LENGTH+INDEX_LENGTH),COUNT(ENGINE),SUM(DATA_LENGTH),SUM(INDEX_LENGTH) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema', 'performance_schema', 'mysql') AND ENGINE IS NOT NULL GROUP BY ENGINE ORDER BY ENGINE ASC;"; "SELECT ENGINE,SUM(DATA_LENGTH+INDEX_LENGTH),COUNT(ENGINE),SUM(DATA_LENGTH),SUM(INDEX_LENGTH) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema', 'performance_schema', 'mysql') AND ENGINE IS NOT NULL GROUP BY ENGINE ORDER BY ENGINE ASC;";
@ -2511,12 +2600,12 @@ sub mariadb_threadpool {
infoprint "Thread Pool Size: ".$myvar{'thread_pool_size'}. " thread(s)."; infoprint "Thread Pool Size: ".$myvar{'thread_pool_size'}. " thread(s).";
if ($myvar{'have_innodb'} eq 'YES') { if ($myvar{'have_innodb'} eq 'YES') {
if ($myvar{'thread_pool_size'}< 16 or $myvar{'thread_pool_size'}>36) { if ($myvar{'thread_pool_size'}< 16 or $myvar{'thread_pool_size'}>36) {
badprint "thread_pool_size between 16 and 36 when using InnoDB storage engine."; badprint "thread_pool_size between 16 and 36 when using InnoDB storage engine.";
push( @generalrec, "Thread pool size for InnoDB usage (".$myvar{'thread_pool_size'}.")" ); push( @generalrec, "Thread pool size for InnoDB usage (".$myvar{'thread_pool_size'}.")" );
push( @adjvars, "thread_pool_size between 16 and 36 for InnoDB usage" ); push( @adjvars, "thread_pool_size between 16 and 36 for InnoDB usage" );
} else { } else {
goodprint "thread_pool_size between 16 and 36 when using InnoDB storage engine."; goodprint "thread_pool_size between 16 and 36 when using InnoDB storage engine.";
} }
return; return;
} }
@ -2539,9 +2628,9 @@ sub mysqsl_pfs {
# Performance Schema # Performance Schema
unless ( defined($myvar{'performance_schema'}) and $myvar{'performance_schema'} eq 'ON' ) { unless ( defined($myvar{'performance_schema'}) and $myvar{'performance_schema'} eq 'ON' ) {
infoprint "Performance schema is disabled."; infoprint "Performance schema is disabled.";
} else {
infoprint "Performance schema is enabled.";
} }
infoprint "Performance schema is enabled.";
} }
@ -2907,7 +2996,7 @@ sub mysql_databases {
$result{'Databases'}{'All databases'}{'Index Pct'} = $result{'Databases'}{'All databases'}{'Index Pct'} =
percentage( $totaldbinfo[2], $totaldbinfo[3] ) . "%"; percentage( $totaldbinfo[2], $totaldbinfo[3] ) . "%";
$result{'Databases'}{'All databases'}{'Total Size'} = $totaldbinfo[3]; $result{'Databases'}{'All databases'}{'Total Size'} = $totaldbinfo[3];
print "\n"; print "\n" unless ($opt{'silent'} or $opt{'json'});
foreach (@dblist) { foreach (@dblist) {
chomp($_); chomp($_);
if ( $_ eq "information_schema" if ( $_ eq "information_schema"
@ -2956,10 +3045,10 @@ sub mysql_databases {
percentage( $dbinfo[3], $dbinfo[4] ) . "%"; percentage( $dbinfo[3], $dbinfo[4] ) . "%";
$result{'Databases'}{ $dbinfo[0] }{'Total Size'} = $dbinfo[4]; $result{'Databases'}{ $dbinfo[0] }{'Total Size'} = $dbinfo[4];
if ($dbinfo[7]>1) { if ($dbinfo[7]>1) {
badprint $dbinfo[7]. " differents collations for database ".$dbinfo[0]; badprint $dbinfo[7]. " differents collations for database ".$dbinfo[0];
push(@generalrec, "Check all table collations are identical for all tables in ".$dbinfo[0]. " database."); push(@generalrec, "Check all table collations are identical for all tables in ".$dbinfo[0]. " database.");
} else { } else {
goodprint $dbinfo[7]. " collation for ".$dbinfo[0]. " database."; goodprint $dbinfo[7]. " collation for ".$dbinfo[0]. " database.";
} }
if ($dbinfo[8]>1) { if ($dbinfo[8]>1) {
badprint $dbinfo[8]. " differents engines for database ".$dbinfo[0]; badprint $dbinfo[8]. " differents engines for database ".$dbinfo[0];
@ -3208,7 +3297,7 @@ sub dump_result {
exit 1; exit 1;
} }
my $json = JSON->new->allow_nonref; my $json = JSON->new->allow_nonref;
print JSON->new->utf8(1)->pretty(1)->encode(%result); print $json->utf8(1)->pretty(($opt{'prettyjson'} ? 1 : 0))->encode(\%result);
} }
} }
@ -3223,7 +3312,7 @@ get_all_vars; # Toss variables/status into hashes
get_tuning_info; # Get information about the tuning connexion get_tuning_info; # Get information about the tuning connexion
validate_mysql_version; # Check current MySQL version validate_mysql_version; # Check current MySQL version
check_architecture; # Suggest 64-bit upgrade check_architecture; # Suggest 64-bit upgrade
system_recommendations; # avoid to many service on the same host system_recommendations; # avoid to many service on the same host
check_storage_engines; # Show enabled storage engines check_storage_engines; # Show enabled storage engines
mysql_databases; # Show informations about databases mysql_databases; # Show informations about databases
mysql_indexes; # Show informations about indexes mysql_indexes; # Show informations about indexes
@ -3277,33 +3366,34 @@ You must provide the remote server's total memory when connecting to other serve
=head1 PERFORMANCE AND REPORTING OPTIONS =head1 PERFORMANCE AND REPORTING OPTIONS
--skipsize Don't enumerate tables and their types/sizes (default: on) --skipsize Don't enumerate tables and their types/sizes (default: on)
(Recommended for servers with many tables) (Recommended for servers with many tables)
--skippassword Don't perform checks on user passwords(default: off) --skippassword Don't perform checks on user passwords(default: off)
--checkversion Check for updates to MySQLTuner (default: don't check) --checkversion Check for updates to MySQLTuner (default: don't check)
--forcemem <size> Amount of RAM installed in megabytes --updateversion Check for updates to MySQLTuner and update when newer version is available (default: don't check)
--forceswap <size> Amount of swap memory configured in megabytes --forcemem <size> Amount of RAM installed in megabytes
--passwordfile <path>Path to a password file list(one password by line) --forceswap <size> Amount of swap memory configured in megabytes
--passwordfile <path> Path to a password file list(one password by line)
=head1 OUTPUT OPTIONS =head1 OUTPUT OPTIONS
--silent Don't output anything on screen --silent Don't output anything on screen
--nogood Remove OK responses --nogood Remove OK responses
--nobad Remove negative/suggestion responses --nobad Remove negative/suggestion responses
--noinfo Remove informational responses --noinfo Remove informational responses
--debug Print debug information --debug Print debug information
--dbstat Print database information --dbstat Print database information
--idxstat Print index information --idxstat Print index information
--bannedports Ports banned separated by comma(,) --bannedports Ports banned separated by comma(,)
--maxportallowed Number of ports opened allowed on this hosts --maxportallowed Number of ports opened allowed on this hosts
--cvefile CVE File for vulnerability checks --cvefile CVE File for vulnerability checks
--nocolor Don't print output in color --nocolor Don't print output in color
--json Print result as JSON string --json Print result as JSON string
--buffers Print global and per-thread buffer values --buffers Print global and per-thread buffer values
--outputfile <path> Path to a output txt file --outputfile <path> Path to a output txt file
--reportfile <path> Path to a report txt file --reportfile <path> Path to a report txt file
--template <path> Path to a template file --template <path> Path to a template file
--verbose Prints out all options (default: no verbose)
=head1 PERLDOC =head1 PERLDOC
You can find documentation for this module with the perldoc command. You can find documentation for this module with the perldoc command.