1
- # !/usr/bin/env perl
2
- # mysqltuner.pl - Version 2.5.1
1
+ # mysqltuner.pl - Version 2.5.2
3
2
# High Performance MySQL Tuning Script
4
3
# Copyright (C) 2015-2023 Jean-Marie Renouard - jmrenouard@gmail.com
5
4
# Copyright (C) 2006-2023 Major Hayden - major@mhtx.net
@@ -57,7 +56,7 @@ package main;
57
56
# use Env;
58
57
59
58
# Set up a few variables for use in the script
60
- my $tunerversion = " 2.5.1 " ;
59
+ my $tunerversion = " 2.5.2 " ;
61
60
my ( @adjvars , @generalrec );
62
61
63
62
# Set defaults
@@ -238,8 +237,9 @@ package main;
238
237
if ( not defined ( $opt {structstat } ) or $opt {nostructstat } == 1 )
239
238
; # Don't print table struct information
240
239
$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
243
243
244
244
# for RPM distributions
245
245
$opt {cvefile } = " /usr/share/mysqltuner/vulnerabilities.csv"
@@ -815,7 +815,8 @@ sub mysql_setup {
815
815
if ( $opt {socket } ne 0 ) {
816
816
if ( $opt {port } ne 0 ) {
817
817
$remotestring = " -S $opt {socket} -P $opt {port}" ;
818
- } else {
818
+ }
819
+ else {
819
820
$remotestring = " -S $opt {socket}" ;
820
821
}
821
822
}
@@ -1580,7 +1581,9 @@ sub log_file_recommendations {
1580
1581
$numLi ++;
1581
1582
debugprint " $numLi : $logLi "
1582
1583
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)/ ;
1584
1587
$nbWarnLog ++ if $logLi =~ / warning/i ;
1585
1588
push @lastShutdowns , $logLi
1586
1589
if $logLi =~ / Shutdown complete/ and $logLi !~ / Innodb/i ;
@@ -2526,7 +2529,7 @@ sub check_architecture {
2526
2529
}
2527
2530
elsif ( ` uname` =~ / Darwin/ && ` uname -m` =~ / x86_64/ ) {
2528
2531
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
2530
2533
$arch = 64;
2531
2534
goodprint " Operating on 64-bit architecture" ;
2532
2535
}
@@ -3180,7 +3183,7 @@ sub calculations {
3180
3183
unless defined $mystat {' Innodb_buffer_pool_reads' };
3181
3184
$mycalc {' pct_read_efficiency' } = percentage(
3182
3185
$mystat {' Innodb_buffer_pool_read_requests' },
3183
- (
3186
+ (
3184
3187
$mystat {' Innodb_buffer_pool_read_requests' } +
3185
3188
$mystat {' Innodb_buffer_pool_reads' }
3186
3189
)
@@ -3211,6 +3214,12 @@ sub calculations {
3211
3214
$mystat {' Innodb_buffer_pool_pages_total' }
3212
3215
) if defined $mystat {' Innodb_buffer_pool_pages_total' };
3213
3216
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
+
3214
3223
# Binlog Cache
3215
3224
if ( $myvar {' log_bin' } ne ' OFF' ) {
3216
3225
$mycalc {' pct_binlog_cache' } = percentage(
@@ -6282,11 +6291,11 @@ sub mysql_innodb {
6282
6291
. hr_bytes( $myvar {' innodb_log_buffer_size' } );
6283
6292
}
6284
6293
if ( defined $mystat {' Innodb_buffer_pool_pages_free' } ) {
6285
- infoprint " +-- InnoDB Log Buffer Free: "
6294
+ infoprint " +-- InnoDB Buffer Free: "
6286
6295
. hr_bytes( $mystat {' Innodb_buffer_pool_pages_free' } ) . " " ;
6287
6296
}
6288
6297
if ( defined $mystat {' Innodb_buffer_pool_pages_total' } ) {
6289
- infoprint " +-- InnoDB Log Buffer Used: "
6298
+ infoprint " +-- InnoDB Buffer Used: "
6290
6299
. hr_bytes( $mystat {' Innodb_buffer_pool_pages_total' } ) . " " ;
6291
6300
}
6292
6301
}
@@ -6355,6 +6364,21 @@ sub mysql_innodb {
6355
6364
. hr_bytes( $enginestats {' InnoDB' } )
6356
6365
. " ) if possible." );
6357
6366
}
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
+ }
6358
6382
if ( $mycalc {' innodb_log_size_pct' } < 20
6359
6383
or $mycalc {' innodb_log_size_pct' } > 30 )
6360
6384
{
@@ -6515,15 +6539,17 @@ sub mysql_innodb {
6515
6539
. $mycalc {' pct_read_efficiency' } . " % ("
6516
6540
. $mystat {' Innodb_buffer_pool_read_requests' }
6517
6541
. " 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' } )
6519
6544
. " total)" ;
6520
6545
}
6521
6546
else {
6522
6547
goodprint " InnoDB Read buffer efficiency: "
6523
6548
. $mycalc {' pct_read_efficiency' } . " % ("
6524
6549
. $mystat {' Innodb_buffer_pool_read_requests' }
6525
6550
. " 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' } )
6527
6553
. " total)" ;
6528
6554
}
6529
6555
@@ -6539,7 +6565,7 @@ sub mysql_innodb {
6539
6565
. $mystat {' Innodb_log_write_requests' }
6540
6566
. " total)" ;
6541
6567
push ( @adjvars ,
6542
- " innodb_log_buffer_size (> "
6568
+ " innodb_log_buffer_size (> "
6543
6569
. hr_bytes_rnd( $myvar {' innodb_log_buffer_size' } )
6544
6570
. " )" );
6545
6571
}
@@ -6691,20 +6717,21 @@ sub mysql_databases {
6691
6717
percentage( $totaldbinfo [2], $totaldbinfo [3] ) . " %" ;
6692
6718
$result {' Databases' }{' All databases' }{' Total Size' } = $totaldbinfo [3];
6693
6719
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
+
6696
6723
foreach (@dblist ) {
6697
6724
my @dbinfo = split /\s /,
6698
6725
select_one(
6699
6726
" 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"
6700
6727
);
6701
6728
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(
6705
6732
" SELECT count(*) from information_schema.TABLES WHERE TABLE_TYPE ='BASE TABLE' AND TABLE_SCHEMA='$_ '"
6706
- );
6707
- infoprint " +-- TABLE : $nbTables " ;
6733
+ );
6734
+ infoprint " +-- TABLE : $nbTables " ;
6708
6735
infoprint " +-- VIEW : "
6709
6736
. select_one(
6710
6737
" SELECT count(*) from information_schema.TABLES WHERE TABLE_TYPE ='VIEW' AND TABLE_SCHEMA='$_ '"
@@ -6760,10 +6787,10 @@ sub mysql_databases {
6760
6787
) . " TABLE(s)" ;
6761
6788
}
6762
6789
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
+ }
6767
6794
badprint " Index size is larger than data size for $dbinfo [0] \n "
6768
6795
if ( $dbinfo [2] ne ' NULL' )
6769
6796
and ( $dbinfo [3] ne ' NULL' )
@@ -6774,7 +6801,7 @@ sub mysql_databases {
6774
6801
. " storage engines. Be careful. \n " ;
6775
6802
push @generalrec ,
6776
6803
" Select one storage engine (InnoDB is a good choice) for all tables in $dbinfo [0] database ($dbinfo [5] engines detected)" ;
6777
- }
6804
+ }
6778
6805
$result {' Databases' }{ $dbinfo [0] }{' Rows' } = $dbinfo [1];
6779
6806
$result {' Databases' }{ $dbinfo [0] }{' Tables' } = $dbinfo [6];
6780
6807
$result {' Databases' }{ $dbinfo [0] }{' Collations' } = $dbinfo [7];
@@ -7078,12 +7105,13 @@ sub mysql_indexes {
7078
7105
infoprint " +-- COMMENT : " . $info [5] if defined $info [5];
7079
7106
$found ++;
7080
7107
}
7081
- my $nbTables = select_one(
7108
+ my $nbTables = select_one(
7082
7109
" 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;
7085
7113
push @generalrec , " Add indexes on tables from $dbname database"
7086
- if $found == 0 and $nbTables > 1;
7114
+ if $found == 0 and $nbTables > 1;
7087
7115
}
7088
7116
return
7089
7117
unless ( defined ( $myvar {' performance_schema' } )
@@ -7371,7 +7399,7 @@ sub which {
7371
7399
7372
7400
=head1 NAME
7373
7401
7374
- MySQLTuner 2.5.1 - MySQL High Performance Tuning Script
7402
+ MySQLTuner 2.5.2 - MySQL High Performance Tuning Script
7375
7403
7376
7404
=head1 IMPORTANT USAGE GUIDELINES
7377
7405
0 commit comments