1- # !/usr/bin/env perl
2- # mysqltuner.pl - Version 2.5.1
1+ # mysqltuner.pl - Version 2.5.2
32# High Performance MySQL Tuning Script
43# Copyright (C) 2015-2023 Jean-Marie Renouard - jmrenouard@gmail.com
54# Copyright (C) 2006-2023 Major Hayden - major@mhtx.net
@@ -57,7 +56,7 @@ package main;
5756# use Env;
5857
5958# Set up a few variables for use in the script
60- my $tunerversion = " 2.5.1 " ;
59+ my $tunerversion = " 2.5.2 " ;
6160my ( @adjvars , @generalrec );
6261
6362# Set defaults
@@ -238,8 +237,9 @@ package main;
238237 if ( not defined ( $opt {structstat } ) or $opt {nostructstat } == 1 )
239238 ; # Don't print table struct information
240239$opt {myisamstat } = 1
241- if ( not defined ( $opt {myisamstat } ));
242- $opt {myisamstat } = 0 if ($opt {nomyisamstat } == 1 ); # Don't print MyISAM table information
240+ if ( not defined ( $opt {myisamstat } ) );
241+ $opt {myisamstat } = 0
242+ if ( $opt {nomyisamstat } == 1 ); # Don't print MyISAM table information
243243
244244# for RPM distributions
245245$opt {cvefile } = " /usr/share/mysqltuner/vulnerabilities.csv"
@@ -815,7 +815,8 @@ sub mysql_setup {
815815 if ( $opt {socket } ne 0 ) {
816816 if ( $opt {port } ne 0 ) {
817817 $remotestring = " -S $opt {socket} -P $opt {port}" ;
818- } else {
818+ }
819+ else {
819820 $remotestring = " -S $opt {socket}" ;
820821 }
821822 }
@@ -1580,7 +1581,9 @@ sub log_file_recommendations {
15801581 $numLi ++;
15811582 debugprint " $numLi : $logLi "
15821583 if $logLi =~ / warning|error/i and $logLi !~ / Logging to/ ;
1583- $nbErrLog ++ if $logLi =~ / error/i and $logLi !~ / (Logging to|\[ Warning\] .*ERROR_FOR_DIVISION_BY_ZERO)/ ;
1584+ $nbErrLog ++
1585+ if $logLi =~ / error/i
1586+ and $logLi !~ / (Logging to|\[ Warning\] .*ERROR_FOR_DIVISION_BY_ZERO)/ ;
15841587 $nbWarnLog ++ if $logLi =~ / warning/i ;
15851588 push @lastShutdowns , $logLi
15861589 if $logLi =~ / Shutdown complete/ and $logLi !~ / Innodb/i ;
@@ -2526,7 +2529,7 @@ sub check_architecture {
25262529 }
25272530 elsif ( ` uname` =~ / Darwin/ && ` uname -m` =~ / x86_64/ ) {
25282531
2529- # Darwin gibas.local 12.5.1 Darwin Kernel Version 12.3.0: Sun Jan 6 22:37:10 PST 2013; root:xnu-2050.22.13~1/RELEASE_X86_64 x86_64
2532+ # Darwin gibas.local 12.5.2 Darwin Kernel Version 12.3.0: Sun Jan 6 22:37:10 PST 2013; root:xnu-2050.22.13~1/RELEASE_X86_64 x86_64
25302533 $arch = 64;
25312534 goodprint " Operating on 64-bit architecture" ;
25322535 }
@@ -3180,7 +3183,7 @@ sub calculations {
31803183 unless defined $mystat {' Innodb_buffer_pool_reads' };
31813184 $mycalc {' pct_read_efficiency' } = percentage(
31823185 $mystat {' Innodb_buffer_pool_read_requests' },
3183- (
3186+ (
31843187 $mystat {' Innodb_buffer_pool_read_requests' } +
31853188 $mystat {' Innodb_buffer_pool_reads' }
31863189 )
@@ -3211,6 +3214,12 @@ sub calculations {
32113214 $mystat {' Innodb_buffer_pool_pages_total' }
32123215 ) if defined $mystat {' Innodb_buffer_pool_pages_total' };
32133216
3217+ $mycalc {' innodb_buffer_alloc_pct' } = select_one(
3218+ " select round( 100* sum(allocated)/( select VARIABLE_VALUE "
3219+ . " FROM performance_schema.global_variables "
3220+ . " WHERE VARIABLE_NAME='innodb_buffer_pool_size' ) ,2)"
3221+ . ' FROM sys.x\$innodb_buffer_stats_by_table;' );
3222+
32143223 # Binlog Cache
32153224 if ( $myvar {' log_bin' } ne ' OFF' ) {
32163225 $mycalc {' pct_binlog_cache' } = percentage(
@@ -6282,11 +6291,11 @@ sub mysql_innodb {
62826291 . hr_bytes( $myvar {' innodb_log_buffer_size' } );
62836292 }
62846293 if ( defined $mystat {' Innodb_buffer_pool_pages_free' } ) {
6285- infoprint " +-- InnoDB Log Buffer Free: "
6294+ infoprint " +-- InnoDB Buffer Free: "
62866295 . hr_bytes( $mystat {' Innodb_buffer_pool_pages_free' } ) . " " ;
62876296 }
62886297 if ( defined $mystat {' Innodb_buffer_pool_pages_total' } ) {
6289- infoprint " +-- InnoDB Log Buffer Used: "
6298+ infoprint " +-- InnoDB Buffer Used: "
62906299 . hr_bytes( $mystat {' Innodb_buffer_pool_pages_total' } ) . " " ;
62916300 }
62926301 }
@@ -6355,6 +6364,21 @@ sub mysql_innodb {
63556364 . hr_bytes( $enginestats {' InnoDB' } )
63566365 . " ) if possible." );
63576366 }
6367+
6368+ # select round( 100* sum(allocated)/( select VARIABLE_VALUE
6369+ # FROM performance_schema.global_variables
6370+ # where VARIABLE_NAME='innodb_buffer_pool_size' )
6371+ # ,2) as "PCT ALLOC/BUFFER POOL"
6372+ # from sys.x$innodb_buffer_stats_by_table;
6373+
6374+ if ( $mycalc {innodb_buffer_alloc_pct } < 80 ) {
6375+ badprint " Ratio Buffer Pool allocated / Buffer Pool Size: "
6376+ . $mycalc {' innodb_buffer_alloc_pct' } . ' %' ;
6377+ }
6378+ else {
6379+ goodprint " Ratio Buffer Pool allocated / Buffer Pool Size: "
6380+ . $mycalc {' innodb_buffer_alloc_pct' } . ' %' ;
6381+ }
63586382 if ( $mycalc {' innodb_log_size_pct' } < 20
63596383 or $mycalc {' innodb_log_size_pct' } > 30 )
63606384 {
@@ -6515,15 +6539,17 @@ sub mysql_innodb {
65156539 . $mycalc {' pct_read_efficiency' } . " % ("
65166540 . $mystat {' Innodb_buffer_pool_read_requests' }
65176541 . " hits / "
6518- . ( $mystat {' Innodb_buffer_pool_reads' } + $mystat {' Innodb_buffer_pool_read_requests' } )
6542+ . ( $mystat {' Innodb_buffer_pool_reads' } +
6543+ $mystat {' Innodb_buffer_pool_read_requests' } )
65196544 . " total)" ;
65206545 }
65216546 else {
65226547 goodprint " InnoDB Read buffer efficiency: "
65236548 . $mycalc {' pct_read_efficiency' } . " % ("
65246549 . $mystat {' Innodb_buffer_pool_read_requests' }
65256550 . " hits / "
6526- . ( $mystat {' Innodb_buffer_pool_reads' } + $mystat {' Innodb_buffer_pool_read_requests' } )
6551+ . ( $mystat {' Innodb_buffer_pool_reads' } +
6552+ $mystat {' Innodb_buffer_pool_read_requests' } )
65276553 . " total)" ;
65286554 }
65296555
@@ -6539,7 +6565,7 @@ sub mysql_innodb {
65396565 . $mystat {' Innodb_log_write_requests' }
65406566 . " total)" ;
65416567 push ( @adjvars ,
6542- " innodb_log_buffer_size (> "
6568+ " innodb_log_buffer_size (> "
65436569 . hr_bytes_rnd( $myvar {' innodb_log_buffer_size' } )
65446570 . " )" );
65456571 }
@@ -6691,20 +6717,21 @@ sub mysql_databases {
66916717 percentage( $totaldbinfo [2], $totaldbinfo [3] ) . " %" ;
66926718 $result {' Databases' }{' All databases' }{' Total Size' } = $totaldbinfo [3];
66936719 print " \n " unless ( $opt {' silent' } or $opt {' json' } );
6694- my $nbViews =0;
6695- my $nbTables =0;
6720+ my $nbViews = 0;
6721+ my $nbTables = 0;
6722+
66966723 foreach (@dblist ) {
66976724 my @dbinfo = split /\s /,
66986725 select_one(
66996726" SELECT TABLE_SCHEMA, SUM(TABLE_ROWS), SUM(DATA_LENGTH), SUM(INDEX_LENGTH), SUM(DATA_LENGTH+INDEX_LENGTH), COUNT(DISTINCT ENGINE), COUNT(TABLE_NAME), COUNT(DISTINCT(TABLE_COLLATION)), COUNT(DISTINCT(ENGINE)) FROM information_schema.TABLES WHERE TABLE_SCHEMA='$_ ' GROUP BY TABLE_SCHEMA ORDER BY TABLE_SCHEMA"
67006727 );
67016728 next unless defined $dbinfo [0];
6702-
6703- infoprint " Database: " . $dbinfo [0] . " " ;
6704- $nbTables = select_one(
6729+
6730+ infoprint " Database: " . $dbinfo [0] . " " ;
6731+ $nbTables = select_one(
67056732" SELECT count(*) from information_schema.TABLES WHERE TABLE_TYPE ='BASE TABLE' AND TABLE_SCHEMA='$_ '"
6706- );
6707- infoprint " +-- TABLE : $nbTables " ;
6733+ );
6734+ infoprint " +-- TABLE : $nbTables " ;
67086735 infoprint " +-- VIEW : "
67096736 . select_one(
67106737" SELECT count(*) from information_schema.TABLES WHERE TABLE_TYPE ='VIEW' AND TABLE_SCHEMA='$_ '"
@@ -6760,10 +6787,10 @@ sub mysql_databases {
67606787 ) . " TABLE(s)" ;
67616788 }
67626789
6763- if ( $nbTables == 0 ) {
6764- badprint " No table in $dbinfo [0] database" ;
6765- next ;
6766- }
6790+ if ( $nbTables == 0 ) {
6791+ badprint " No table in $dbinfo [0] database" ;
6792+ next ;
6793+ }
67676794 badprint " Index size is larger than data size for $dbinfo [0] \n "
67686795 if ( $dbinfo [2] ne ' NULL' )
67696796 and ( $dbinfo [3] ne ' NULL' )
@@ -6774,7 +6801,7 @@ sub mysql_databases {
67746801 . " storage engines. Be careful. \n " ;
67756802 push @generalrec ,
67766803" Select one storage engine (InnoDB is a good choice) for all tables in $dbinfo [0] database ($dbinfo [5] engines detected)" ;
6777- }
6804+ }
67786805 $result {' Databases' }{ $dbinfo [0] }{' Rows' } = $dbinfo [1];
67796806 $result {' Databases' }{ $dbinfo [0] }{' Tables' } = $dbinfo [6];
67806807 $result {' Databases' }{ $dbinfo [0] }{' Collations' } = $dbinfo [7];
@@ -7078,12 +7105,13 @@ sub mysql_indexes {
70787105 infoprint " +-- COMMENT : " . $info [5] if defined $info [5];
70797106 $found ++;
70807107 }
7081- my $nbTables = select_one(
7108+ my $nbTables = select_one(
70827109" SELECT count(*) from information_schema.TABLES WHERE TABLE_TYPE ='BASE TABLE' AND TABLE_SCHEMA='$dbname '"
7083- );
7084- badprint " No index found for $dbname database" if $found == 0 and $nbTables >1;
7110+ );
7111+ badprint " No index found for $dbname database"
7112+ if $found == 0 and $nbTables > 1;
70857113 push @generalrec , " Add indexes on tables from $dbname database"
7086- if $found == 0 and $nbTables > 1;
7114+ if $found == 0 and $nbTables > 1;
70877115 }
70887116 return
70897117 unless ( defined ( $myvar {' performance_schema' } )
@@ -7371,7 +7399,7 @@ sub which {
73717399
73727400=head1 NAME
73737401
7374- MySQLTuner 2.5.1 - MySQL High Performance Tuning Script
7402+ MySQLTuner 2.5.2 - MySQL High Performance Tuning Script
73757403
73767404=head1 IMPORTANT USAGE GUIDELINES
73777405
0 commit comments