Last modification related to options

This commit is contained in:
Jean-Marie Renouard 2018-11-26 12:57:11 +00:00
parent 0f724fa31f
commit 1b9e4e75ba
2 changed files with 123 additions and 83 deletions

View file

@ -1,6 +1,6 @@
# NAME
MySQLTuner 1.7.11 - MySQL High Performance Tuning Script
MySQLTuner 1.7.14 - MySQL High Performance Tuning Script
# IMPORTANT USAGE GUIDELINES
@ -41,12 +41,19 @@ You must provide the remote server's total memory when connecting to other serve
--nobad Remove negative/suggestion responses
--noinfo Remove informational responses
--debug Print debug information
--noprocess Consider no other process is running
--dbstat Print database information
--nodbstat Don't Print database information
--tbstat Print table information
--notbstat Don't Print table information
--idxstat Print index information
--noidxstat Don't Print index information
--sysstat Print system information
--nosysstat Don't Print system information
--pfstat Print Performance schema
--nopfstat Don't Print Performance schema
--verbose Prints out all options (default: no verbose, dbstat, idxstat, sysstat, tbstat, pfstat)
--bannedports Ports banned separated by comma(,)
--maxportallowed Number of ports opened allowed on this hosts
--cvefile <path> CVE File for vulnerability checks
@ -56,7 +63,6 @@ You must provide the remote server's total memory when connecting to other serve
--outputfile <path> Path to a output txt file
--reportfile <path> Path to a report txt file
--template <path> Path to a template file
--verbose Prints out all options (default: no verbose)
# PERLDOC

View file

@ -1,5 +1,5 @@
#!/usr/bin/env perl
# mysqltuner.pl - Version 1.7.13
# mysqltuner.pl - Version 1.7.14
# High Performance MySQL Tuning Script
# Copyright (C) 2006-2018 Major Hayden - major@mhtx.net
#
@ -56,7 +56,7 @@ $Data::Dumper::Pair = " : ";
#use Env;
# Set up a few variables for use in the script
my $tunerversion = "1.7.13";
my $tunerversion = "1.7.14";
my ( @adjvars, @generalrec );
# Set defaults
@ -85,12 +85,17 @@ my %opt = (
"bannedports" => '',
"maxportallowed" => 0,
"outputfile" => 0,
"noprocess" => 0,
"dbstat" => 0,
"nodbstat" => 0,
"tbstat" => 0,
"notbstat" => 0,
"idxstat" => 0,
"noidxstat" => 0,
"sysstat" => 0,
"nosysstat" => 0,
"pfstat" => 0,
"nopfstat" => 0,
"skippassword" => 0,
"noask" => 0,
"template" => 0,
@ -114,18 +119,20 @@ GetOptions(
'mysqlcmd=s', 'help',
'buffers', 'skippassword',
'passwordfile=s', 'outputfile=s',
'silent', 'dbstat',
'silent', 'noask',
'json', 'prettyjson',
'idxstat', 'noask',
'template=s', 'reportfile=s',
'cvefile=s', 'bannedports=s',
'updateversion', 'maxportallowed=s',
'verbose', 'sysstat',
'password=s', 'pfstat',
'verbose', 'password=s',
'passenv=s', 'userenv=s',
'defaults-file=s', 'ssl-ca=s',
'color', 'tbstat',
'notbstat'
'color', 'noprocess',
'dbstat', 'nodbstat',
'tbstat', 'notbstat',
'sysstat', 'nosysstat',
'pfstat', 'nopfstat',
'idxstat', 'noidxstat',
)
or pod2usage(
-exitval => 1,
@ -185,9 +192,16 @@ if ( $opt{verbose} ) {
$opt{pfstat} = 1; #Print performance schema info.
$opt{cvefile} = 'vulnerabilities.csv'; #CVE File for vulnerability checks
}
$opt{nocolor} = 1 if defined($opt{outputfile});
$opt{tbstat} = 1 if ($opt{notbstat} != 0); # Don't Print database information
$opt{nocolor} = 1 if defined( $opt{outputfile} );
$opt{tbstat} = 0 if ( $opt{notbstat} == 1 ); # Don't Print table information
$opt{dbstat} = 0 if ( $opt{nodbstat} == 1 ); # Don't Print database information
$opt{noprocess} = 0
if ( $opt{noprocess} == 1 ); # Don't Print process information
$opt{sysstat} = 0 if ( $opt{nosysstat} == 1 ); # Don't Print sysstat information
$opt{pfstat} = 0
if ( $opt{nopfstat} == 1 ); # Don't Print performance schema information
$opt{idxstat} = 0 if ( $opt{noidxstat} == 1 ); # Don't Print index information
# for RPM distributions
$opt{cvefile} = "/usr/share/mysqltuner/vulnerabilities.csv"
unless ( defined $opt{cvefile} and -f "$opt{cvefile}" );
@ -841,7 +855,8 @@ sub mysql_setup {
return 1;
}
else {
badprint "Attempted to use login credentials from Debian maintenance account, but they failed.";
badprint
"Attempted to use login credentials from Debian maintenance account, but they failed.";
exit 1;
}
}
@ -963,10 +978,9 @@ sub select_array {
}
sub human_size {
my( $size, $n ) =( shift, 0 );
my ( $size, $n ) = ( shift, 0 );
++$n and $size /= 1024 until $size < 1024;
return sprintf "%.2f %s",
$size, ( qw[ bytes KB MB GB ] )[ $n ];
return sprintf "%.2f %s", $size, (qw[ bytes KB MB GB ])[$n];
}
# MySQL Request one
@ -1080,13 +1094,13 @@ sub get_all_vars {
push( @mysqlstatlist, select_array("SHOW GLOBAL STATUS") );
arr2hash( \%mystat, \@mysqlstatlist );
$result{'Status'} = \%mystat;
unless( defined ($myvar{'innodb_support_xa'}) ) {
$myvar{'innodb_support_xa'}='ON';
unless ( defined( $myvar{'innodb_support_xa'} ) ) {
$myvar{'innodb_support_xa'} = 'ON';
}
$myvar{'have_galera'} = "NO";
if ( defined( $myvar{'wsrep_provider_options'} )
&& $myvar{'wsrep_provider_options'} ne ""
if ( defined( $myvar{'wsrep_provider_options'} )
&& $myvar{'wsrep_provider_options'} ne ""
&& $myvar{'wsrep_on'} ne "OFF" )
{
$myvar{'have_galera'} = "YES";
@ -1373,6 +1387,7 @@ sub get_process_memory {
}
sub get_other_process_memory {
return 0 if ( $opt{tbstat} == 0 );
my @procs = `ps eaxo pid,command`;
@procs = map {
my $v = $_;
@ -1630,7 +1645,7 @@ sub get_system_info {
infoprint "System Uptime : ";
infocmd_tab "uptime";
$result{'OS'}{'Uptime'}= `uptime`;
$result{'OS'}{'Uptime'} = `uptime`;
}
sub system_recommendations {
@ -1709,11 +1724,12 @@ sub system_recommendations {
sub security_recommendations {
subheaderprint "Security Recommendations";
if ( mysql_version_eq(8) ) {
infoprint "Skipped due to unsupported feature for MySQL 8";
return;
}
#exit 0;
if ( $opt{skippassword} eq 1 ) {
infoprint "Skipped due to --skippassword option";
@ -1912,7 +1928,7 @@ sub get_replication_status {
"This replication slave is not running but seems to be configured.";
}
if ( defined($io_running)
&& $io_running =~ /yes/i
&& $io_running =~ /yes/i
&& $sql_running =~ /yes/i )
{
if ( $myvar{'read_only'} eq 'OFF' ) {
@ -1958,8 +1974,10 @@ sub validate_mysql_version {
# Checks if MySQL version is equal to (major, minor, micro)
sub mysql_version_eq {
my ( $maj, $min, $mic ) = @_;
return int($mysqlvermajor) == int($maj) if ( !defined($min) && !defined($mic));
return int($mysqlvermajor) == int($maj)&& int($mysqlverminor) == int($min) if ( !defined($mic));
return int($mysqlvermajor) == int($maj)
if ( !defined($min) && !defined($mic) );
return int($mysqlvermajor) == int($maj) && int($mysqlverminor) == int($min)
if ( !defined($mic) );
return ( int($mysqlvermajor) == int($maj)
&& int($mysqlverminor) == int($min)
&& int($mysqlvermicro) == int($mic) );
@ -2190,7 +2208,7 @@ sub check_storage_engines {
debugprint "Data dump " . Dumper(@$tbl);
my ( $engine, $size, $datafree ) = @$tbl;
next if $engine eq 'NULL';
$size = 0 if $size eq 'NULL';
$size = 0 if $size eq 'NULL';
$datafree = 0 if $datafree eq 'NULL';
if ( defined $enginestats{$engine} ) {
$enginestats{$engine} += $size;
@ -2374,6 +2392,7 @@ sub calculations {
$mycalc{'server_buffers'} +
$mycalc{"max_total_per_thread_buffers"} +
get_pf_memory();
# + get_gcache_memory();
$mycalc{'pct_max_used_memory'} =
percentage( $mycalc{'max_used_memory'}, $physical_memory );
@ -2384,7 +2403,8 @@ sub calculations {
$mycalc{'server_buffers'} +
$mycalc{'total_per_thread_buffers'} +
get_pf_memory();
# + get_gcache_memory();
# + get_gcache_memory();
$mycalc{'pct_max_physical_memory'} =
percentage( $mycalc{'max_peak_memory'}, $physical_memory );
@ -2429,7 +2449,7 @@ sub calculations {
$myvar{'key_cache_block_size'}
) / $myvar{'key_buffer_size'}
)
) * 100
) * 100
);
}
else {
@ -2512,20 +2532,21 @@ sub calculations {
# Query cache
if ( mysql_version_ge(8) and mysql_version_le(10) ) {
$mycalc{'query_cache_efficiency'} = 0;
} elsif ( mysql_version_ge(4) ) {
}
elsif ( mysql_version_ge(4) ) {
$mycalc{'query_cache_efficiency'} = sprintf(
"%.1f",
(
$mystat{'Qcache_hits'} /
( $mystat{'Com_select'} + $mystat{'Qcache_hits'} )
) * 100
) * 100
);
if ( $myvar{'query_cache_size'} ) {
$mycalc{'pct_query_cache_used'} = sprintf(
"%.1f",
100 - (
$mystat{'Qcache_free_memory'} / $myvar{'query_cache_size'}
) * 100
) * 100
);
}
if ( $mystat{'Qcache_lowmem_prunes'} == 0 ) {
@ -2724,17 +2745,15 @@ sub mysql_stats {
infoprint "Max MySQL memory : " . hr_bytes( $mycalc{'max_peak_memory'} );
infoprint "Other process memory: " . hr_bytes( get_other_process_memory() );
#print hr_bytes( $mycalc{'server_buffers'} );
infoprint "Total buffers: "
. hr_bytes( $mycalc{'server_buffers'} )
. " global + "
. hr_bytes( $mycalc{'per_thread_buffers'} )
. " per thread ($myvar{'max_connections'} max threads)";
infoprint "P_S Max memory usage: " . hr_bytes_rnd( get_pf_memory() );
$result{'P_S'}{'memory'} = get_other_process_memory();
$result{'P_S'}{'memory'} = get_pf_memory();
$result{'P_S'}{'pretty_memory'} =
hr_bytes_rnd( get_other_process_memory() );
hr_bytes_rnd( get_pf_memory() );
infoprint "Galera GCache Max memory usage: "
. hr_bytes_rnd( get_gcache_memory() );
$result{'Galera'}{'GCache'}{'memory'} = get_gcache_memory();
@ -2750,7 +2769,7 @@ sub mysql_stats {
if ( defined $myvar{'query_cache_type'} ) {
infoprint "Query Cache Buffers";
infoprint " +-- Query Cache: "
infoprint " +-- Query Cache: "
. $myvar{'query_cache_type'} . " - "
. (
$myvar{'query_cache_type'} eq 0 |
@ -2901,12 +2920,14 @@ sub mysql_stats {
# Query cache
if ( !mysql_version_ge(4) ) {
# MySQL versions < 4.01 don't support query caching
push( @generalrec,
"Upgrade MySQL to version 4+ to utilize query caching" );
}
elsif (mysql_version_eq(8)) {
elsif ( mysql_version_eq(8) ) {
infoprint "Query cache have been removed in MySQL 8";
#return;
}
elsif ( $myvar{'query_cache_size'} < 1
@ -3073,17 +3094,18 @@ sub mysql_stats {
if ( defined( $myvar{'thread_handling'} )
and $myvar{'thread_handling'} eq 'pool-of-threads' )
{
# https://www.percona.com/doc/percona-server/LATEST/performance/threadpool.html
# When thread pool is enabled, the value of the thread_cache_size variable
# is ignored. The Threads_cached status variable contains 0 in this case.
# https://www.percona.com/doc/percona-server/LATEST/performance/threadpool.html
# When thread pool is enabled, the value of the thread_cache_size variable
# is ignored. The Threads_cached status variable contains 0 in this case.
infoprint "Thread cache not used with thread_handling=pool-of-threads";
}
else {
if ( $myvar{'thread_cache_size'} eq 0 ) {
badprint "Thread cache is disabled";
push( @generalrec, "Set thread_cache_size to 4 as a starting value" );
push( @adjvars, "thread_cache_size (start at 4)" );
}
push( @generalrec,
"Set thread_cache_size to 4 as a starting value" );
push( @adjvars, "thread_cache_size (start at 4)" );
}
else {
if ( $mycalc{'thread_cache_hit_rate'} <= 50 ) {
badprint
@ -3134,7 +3156,8 @@ sub mysql_stats {
. " over 64: http://bit.ly/1mi7c4C" );
push( @generalrec,
"Read this before increasing for MariaDB"
. " https://mariadb.com/kb/en/library/optimizing-table_open_cache/");
. " https://mariadb.com/kb/en/library/optimizing-table_open_cache/"
);
push( @generalrec,
"This is MyISAM only table_cache scalability problem, InnoDB not affected."
);
@ -5171,8 +5194,9 @@ sub mariadb_galera {
}
infoprint "GCache is using "
. hr_bytes_rnd( get_wsrep_option('gcache.mem_size') );
#my @primaryKeysNbTables=();
my @primaryKeysNbTables = select_array(
#my @primaryKeysNbTables=();
my @primaryKeysNbTables = select_array(
"Select CONCAT(c.table_schema,CONCAT('.', c.table_name))
from information_schema.columns c
join information_schema.tables t using (TABLE_SCHEMA, TABLE_NAME)
@ -5182,15 +5206,14 @@ group by c.table_schema,c.table_name
having sum(if(c.column_key in ('PRI','UNI'), 1,0)) = 0"
);
infoprint "CPU core detected : ". (cpu_cores);
infoprint "wsrep_slave_threads: ". get_wsrep_option('wsrep_slave_threads');
if ( get_wsrep_option('wsrep_slave_threads') > ((cpu_cores) * 4)
or get_wsrep_option('wsrep_slave_threads') < ((cpu_cores) * 2) )
infoprint "CPU core detected : " . (cpu_cores);
infoprint "wsrep_slave_threads: " . get_wsrep_option('wsrep_slave_threads');
if ( get_wsrep_option('wsrep_slave_threads') > ( (cpu_cores) * 4 )
or get_wsrep_option('wsrep_slave_threads') < ( (cpu_cores) * 2 ) )
{
badprint
"wsrep_slave_threads is not equal to 2, 3 or 4 times number of CPU(s)";
push @adjvars, "wsrep_slave_threads = ".((cpu_cores) * 4);
push @adjvars, "wsrep_slave_threads = " . ( (cpu_cores) * 4 );
}
else {
goodprint
@ -5736,17 +5759,19 @@ sub mysql_innodb {
sub check_metadata_perf {
subheaderprint "Analysis Performance Metrics";
infoprint "innodb_stats_on_metadata: ".$myvar{'innodb_stats_on_metadata'};
if ($myvar{'innodb_stats_on_metadata'} eq 'ON') {
infoprint "innodb_stats_on_metadata: " . $myvar{'innodb_stats_on_metadata'};
if ( $myvar{'innodb_stats_on_metadata'} eq 'ON' ) {
badprint "Stat are updated during querying INFORMATION_SCHEMA.";
push @adjvars, "SET innodb_stats_on_metadata = OFF";
#Disabling innodb_stats_on_metadata
#Disabling innodb_stats_on_metadata
select_one("SET GLOBAL innodb_stats_on_metadata = OFF;");
return 1;
}
goodprint "No stat updates during querying INFORMATION_SCHEMA.";
return 0
return 0;
}
# Recommendations for Database metrics
sub mysql_databases {
return if ( $opt{dbstat} == 0 );
@ -6197,29 +6222,30 @@ sub dump_result {
open my $fh, q(>), $opt{'reportfile'}
or die
"Unable to open $opt{'reportfile'} in write mode. please check permissions for this file or directory";
"Unable to open $opt{'reportfile'} in write mode. please check permissions for this file or directory";
$template->fill_in( HASH => $vars, OUTPUT => $fh );
close $fh;
}
if ( $opt{'json'} ne 0 ) {
eval { require JSON };
if ($@) {
if ($@) {
print "$bad JSON Module is needed.\n";
return 1;
}
my $json = JSON->new->allow_nonref;
print $json->utf8(1)->pretty( ( $opt{'prettyjson'} ? 1 : 0 ) )->encode( \%result );
print $json->utf8(1)->pretty( ( $opt{'prettyjson'} ? 1 : 0 ) )
->encode( \%result );
if ( $opt{'outputfile'} ne 0 ) {
unlink $opt{'outputfile'} if (-e $opt{'outputfile'});
unlink $opt{'outputfile'} if ( -e $opt{'outputfile'} );
open my $fh, q(>), $opt{'outputfile'}
or die
"Unable to open $opt{'outputfile'} in write mode. please check permissions for this file or directory";
print $fh $json->utf8(1)->pretty( ( $opt{'prettyjson'} ? 1 : 0 ) )->encode( \%result );
close $fh;
"Unable to open $opt{'outputfile'} in write mode. please check permissions for this file or directory";
print $fh $json->utf8(1)->pretty( ( $opt{'prettyjson'} ? 1 : 0 ) )
->encode( \%result );
close $fh;
}
}
}
@ -6257,22 +6283,23 @@ system_recommendations; # avoid to many service on the same host
log_file_recommendations; # check log file content
check_storage_engines; # Show enabled storage engines
check_metadata_perf; # Show parameter impacting performance during analysis
mysql_databases; # Show informations about databases
mysql_tables; # Show informations about table column
check_metadata_perf; # Show parameter impacting performance during analysis
mysql_databases; # Show informations about databases
mysql_tables; # Show informations about table column
mysql_indexes; # Show informations about indexes
security_recommendations; # Display some security recommendations
cve_recommendations; # Display related CVE
calculations; # Calculate everything we need
mysql_stats; # Print the server stats
mysqsl_pfs; # Print Performance schema info
mariadb_threadpool; # Print MariaDB ThreadPool stats
mysql_myisam; # Print MyISAM stats
mysql_innodb; # Print InnoDB stats
mariadb_ariadb; # Print MariaDB AriaDB stats
mariadb_tokudb; # Print MariaDB Tokudb stats
mariadb_xtradb; # Print MariaDB XtraDB stats
mysql_indexes; # Show informations about indexes
security_recommendations; # Display some security recommendations
cve_recommendations; # Display related CVE
calculations; # Calculate everything we need
mysql_stats; # Print the server stats
mysqsl_pfs; # Print Performance schema info
mariadb_threadpool; # Print MariaDB ThreadPool stats
mysql_myisam; # Print MyISAM stats
mysql_innodb; # Print InnoDB stats
mariadb_ariadb; # Print MariaDB AriaDB stats
mariadb_tokudb; # Print MariaDB Tokudb stats
mariadb_xtradb; # Print MariaDB XtraDB stats
#mariadb_rockdb; # Print MariaDB RockDB stats
#mariadb_spider; # Print MariaDB Spider stats
#mariadb_connect; # Print MariaDB Connect stats
@ -6295,7 +6322,7 @@ __END__
=head1 NAME
MySQLTuner 1.7.13 - MySQL High Performance Tuning Script
MySQLTuner 1.7.14 - MySQL High Performance Tuning Script
=head1 IMPORTANT USAGE GUIDELINES
@ -6336,12 +6363,19 @@ You must provide the remote server's total memory when connecting to other serve
--nobad Remove negative/suggestion responses
--noinfo Remove informational responses
--debug Print debug information
--noprocess Consider no other process is running
--dbstat Print database information
--nodbstat Don't Print database information
--tbstat Print table information
--notbstat Don't Print table information
--idxstat Print index information
--noidxstat Don't Print index information
--sysstat Print system information
--nosysstat Don't Print system information
--pfstat Print Performance schema
--nopfstat Don't Print Performance schema
--verbose Prints out all options (default: no verbose, dbstat, idxstat, sysstat, tbstat, pfstat)
--bannedports Ports banned separated by comma(,)
--maxportallowed Number of ports opened allowed on this hosts
--cvefile <path> CVE File for vulnerability checks
@ -6351,7 +6385,7 @@ You must provide the remote server's total memory when connecting to other serve
--outputfile <path> Path to a output txt file
--reportfile <path> Path to a report txt file
--template <path> Path to a template file
--verbose Prints out all options (default: no verbose)
=head1 PERLDOC
@ -6528,7 +6562,7 @@ L<https://github.com/major/MySQLTuner-perl>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2006-2017 Major Hayden - major@mhtx.net
Copyright (C) 2006-2018 Major Hayden - major@mhtx.net
For the latest updates, please visit http://mysqltuner.com/