@@ -196,7 +196,7 @@ package main;
196
196
$opt {pass } = $opt {password } if ( $opt {pass } eq 0 and $opt {password } ne 0 );
197
197
198
198
if ( $opt {dumpdir } ne ' ' ) {
199
- $opt {dumpdir }= abs_path($opt {dumpdir });
199
+ $opt {dumpdir } = abs_path( $opt {dumpdir } );
200
200
if ( !-d $opt {dumpdir } ) {
201
201
mkdir $opt {dumpdir } or die " Cannot create directory $opt {dumpdir}: $! " ;
202
202
}
@@ -237,8 +237,9 @@ package main;
237
237
if ( not defined ( $opt {structstat } ) or $opt {nostructstat } == 1 )
238
238
; # Don't print table struct information
239
239
$opt {myisamstat } = 1
240
- if ( not defined ( $opt {myisamstat } ));
241
- $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
242
243
243
244
# for RPM distributions
244
245
$opt {cvefile } = " /usr/share/mysqltuner/vulnerabilities.csv"
@@ -814,7 +815,8 @@ sub mysql_setup {
814
815
if ( $opt {socket } ne 0 ) {
815
816
if ( $opt {port } ne 0 ) {
816
817
$remotestring = " -S $opt {socket} -P $opt {port}" ;
817
- } else {
818
+ }
819
+ else {
818
820
$remotestring = " -S $opt {socket}" ;
819
821
}
820
822
}
@@ -1579,7 +1581,9 @@ sub log_file_recommendations {
1579
1581
$numLi ++;
1580
1582
debugprint " $numLi : $logLi "
1581
1583
if $logLi =~ / warning|error/i and $logLi !~ / Logging to/ ;
1582
- $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)/ ;
1583
1587
$nbWarnLog ++ if $logLi =~ / warning/i ;
1584
1588
push @lastShutdowns , $logLi
1585
1589
if $logLi =~ / Shutdown complete/ and $logLi !~ / Innodb/i ;
@@ -3179,7 +3183,7 @@ sub calculations {
3179
3183
unless defined $mystat {' Innodb_buffer_pool_reads' };
3180
3184
$mycalc {' pct_read_efficiency' } = percentage(
3181
3185
$mystat {' Innodb_buffer_pool_read_requests' },
3182
- (
3186
+ (
3183
3187
$mystat {' Innodb_buffer_pool_read_requests' } +
3184
3188
$mystat {' Innodb_buffer_pool_reads' }
3185
3189
)
@@ -3210,11 +3214,12 @@ sub calculations {
3210
3214
$mystat {' Innodb_buffer_pool_pages_total' }
3211
3215
) if defined $mystat {' Innodb_buffer_pool_pages_total' };
3212
3216
3213
- $mycalc {' innodb_buffer_alloc_pct' }=select_one(
3214
- " select round( 100* sum(allocated)/( select VARIABLE_VALUE " .
3215
- " FROM performance_schema.global_variables " .
3216
- " WHERE VARIABLE_NAME='innodb_buffer_pool_size' ) ,2)" .
3217
- ' FROM sys.x\$innodb_buffer_stats_by_table;' );
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
+
3218
3223
# Binlog Cache
3219
3224
if ( $myvar {' log_bin' } ne ' OFF' ) {
3220
3225
$mycalc {' pct_binlog_cache' } = percentage(
@@ -6360,59 +6365,60 @@ sub mysql_innodb {
6360
6365
. " ) if possible." );
6361
6366
}
6362
6367
6363
- # select round( 100* sum(allocated)/( select VARIABLE_VALUE
6364
- # FROM performance_schema.global_variables
6365
- # where VARIABLE_NAME='innodb_buffer_pool_size' )
6366
- # ,2) as "PCT ALLOC/BUFFER POOL"
6367
- # from sys.x$innodb_buffer_stats_by_table;
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;
6368
6373
6369
- if ($mycalc {innodb_buffer_alloc_pct } < 80) {
6370
- badprint " Ratio Buffer Pool allocated / Buffer Pool Size: " .
6371
- $mycalc {' innodb_buffer_alloc_pct' } . ' %' ;
6372
- } else {
6373
- goodprint " Ratio Buffer Pool allocated / Buffer Pool Size: " .
6374
- $mycalc {' innodb_buffer_alloc_pct' } . ' %' ;
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' } . ' %' ;
6375
6381
}
6376
6382
if ( $mycalc {' innodb_log_size_pct' } < 20
6377
6383
or $mycalc {' innodb_log_size_pct' } > 30 )
6378
6384
{
6379
- if ( defined $myvar {' innodb_redo_log_capacity' } ) {
6380
- badprint
6381
- " Ratio InnoDB redo log capacity / InnoDB Buffer pool size ("
6382
- . $mycalc {' innodb_log_size_pct' } . " %): "
6383
- . hr_bytes( $myvar {' innodb_redo_log_capacity' } ) . " / "
6384
- . hr_bytes( $myvar {' innodb_buffer_pool_size' } )
6385
- . " should be equal to 25%" ;
6386
- push ( @adjvars ,
6387
- " innodb_redo_log_capacity should be (="
6388
- . hr_bytes_rnd( $myvar {' innodb_buffer_pool_size' } / 4 )
6389
- . " ) if possible, so InnoDB Redo log Capacity equals 25% of buffer pool size."
6390
- );
6391
- push ( @generalrec ,
6392
- " Be careful, increasing innodb_redo_log_capacity means higher crash recovery mean time"
6393
- );
6394
- }
6395
- else {
6396
- badprint " Ratio InnoDB log file size / InnoDB Buffer pool size ("
6397
- . $mycalc {' innodb_log_size_pct' } . " %): "
6398
- . hr_bytes( $myvar {' innodb_log_file_size' } ) . " * "
6399
- . $myvar {' innodb_log_files_in_group' } . " / "
6400
- . hr_bytes( $myvar {' innodb_buffer_pool_size' } )
6401
- . " should be equal to 25%" ;
6402
- push (
6403
- @adjvars ,
6404
- " innodb_log_file_size should be (="
6405
- . hr_bytes_rnd(
6406
- $myvar {' innodb_buffer_pool_size' } /
6407
- $myvar {' innodb_log_files_in_group' } / 4
6408
- )
6409
- . " ) if possible, so InnoDB total log file size equals 25% of buffer pool size."
6410
- );
6411
- push ( @generalrec ,
6412
- " Be careful, increasing innodb_log_file_size / innodb_log_files_in_group means higher crash recovery mean time"
6413
- );
6414
- }
6415
- if ( mysql_version_le( 5, 6, 2 ) ) {
6385
+ if ( defined $myvar {' innodb_redo_log_capacity' } ) {
6386
+ badprint
6387
+ " Ratio InnoDB redo log capacity / InnoDB Buffer pool size ("
6388
+ . $mycalc {' innodb_log_size_pct' } . " %): "
6389
+ . hr_bytes( $myvar {' innodb_redo_log_capacity' } ) . " / "
6390
+ . hr_bytes( $myvar {' innodb_buffer_pool_size' } )
6391
+ . " should be equal to 25%" ;
6392
+ push ( @adjvars ,
6393
+ " innodb_redo_log_capacity should be (="
6394
+ . hr_bytes_rnd( $myvar {' innodb_buffer_pool_size' } / 4 )
6395
+ . " ) if possible, so InnoDB Redo log Capacity equals 25% of buffer pool size."
6396
+ );
6397
+ push ( @generalrec ,
6398
+ " Be careful, increasing innodb_redo_log_capacity means higher crash recovery mean time"
6399
+ );
6400
+ }
6401
+ else {
6402
+ badprint " Ratio InnoDB log file size / InnoDB Buffer pool size ("
6403
+ . $mycalc {' innodb_log_size_pct' } . " %): "
6404
+ . hr_bytes( $myvar {' innodb_log_file_size' } ) . " * "
6405
+ . $myvar {' innodb_log_files_in_group' } . " / "
6406
+ . hr_bytes( $myvar {' innodb_buffer_pool_size' } )
6407
+ . " should be equal to 25%" ;
6408
+ push (
6409
+ @adjvars ,
6410
+ " innodb_log_file_size should be (="
6411
+ . hr_bytes_rnd(
6412
+ $myvar {' innodb_buffer_pool_size' } /
6413
+ $myvar {' innodb_log_files_in_group' } / 4
6414
+ )
6415
+ . " ) if possible, so InnoDB total log file size equals 25% of buffer pool size."
6416
+ );
6417
+ push ( @generalrec ,
6418
+ " Be careful, increasing innodb_log_file_size / innodb_log_files_in_group means higher crash recovery mean time"
6419
+ );
6420
+ }
6421
+ if ( mysql_version_le( 5, 6, 2 ) ) {
6416
6422
push ( @generalrec ,
6417
6423
" For MySQL 5.6.2 and lower, total innodb_log_file_size should have a ceiling of (4096MB / log files in group) - 1MB."
6418
6424
);
@@ -6533,15 +6539,17 @@ sub mysql_innodb {
6533
6539
. $mycalc {' pct_read_efficiency' } . " % ("
6534
6540
. $mystat {' Innodb_buffer_pool_read_requests' }
6535
6541
. " hits / "
6536
- . ( $mystat {' Innodb_buffer_pool_reads' } + $mystat {' Innodb_buffer_pool_read_requests' } )
6542
+ . ( $mystat {' Innodb_buffer_pool_reads' } +
6543
+ $mystat {' Innodb_buffer_pool_read_requests' } )
6537
6544
. " total)" ;
6538
6545
}
6539
6546
else {
6540
6547
goodprint " InnoDB Read buffer efficiency: "
6541
6548
. $mycalc {' pct_read_efficiency' } . " % ("
6542
6549
. $mystat {' Innodb_buffer_pool_read_requests' }
6543
6550
. " hits / "
6544
- . ( $mystat {' Innodb_buffer_pool_reads' } + $mystat {' Innodb_buffer_pool_read_requests' } )
6551
+ . ( $mystat {' Innodb_buffer_pool_reads' } +
6552
+ $mystat {' Innodb_buffer_pool_read_requests' } )
6545
6553
. " total)" ;
6546
6554
}
6547
6555
@@ -6557,7 +6565,7 @@ sub mysql_innodb {
6557
6565
. $mystat {' Innodb_log_write_requests' }
6558
6566
. " total)" ;
6559
6567
push ( @adjvars ,
6560
- " innodb_log_buffer_size (> "
6568
+ " innodb_log_buffer_size (> "
6561
6569
. hr_bytes_rnd( $myvar {' innodb_log_buffer_size' } )
6562
6570
. " )" );
6563
6571
}
@@ -6709,20 +6717,21 @@ sub mysql_databases {
6709
6717
percentage( $totaldbinfo [2], $totaldbinfo [3] ) . " %" ;
6710
6718
$result {' Databases' }{' All databases' }{' Total Size' } = $totaldbinfo [3];
6711
6719
print " \n " unless ( $opt {' silent' } or $opt {' json' } );
6712
- my $nbViews =0;
6713
- my $nbTables =0;
6720
+ my $nbViews = 0;
6721
+ my $nbTables = 0;
6722
+
6714
6723
foreach (@dblist ) {
6715
6724
my @dbinfo = split /\s /,
6716
6725
select_one(
6717
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"
6718
6727
);
6719
6728
next unless defined $dbinfo [0];
6720
-
6721
- infoprint " Database: " . $dbinfo [0] . " " ;
6722
- $nbTables = select_one(
6729
+
6730
+ infoprint " Database: " . $dbinfo [0] . " " ;
6731
+ $nbTables = select_one(
6723
6732
" SELECT count(*) from information_schema.TABLES WHERE TABLE_TYPE ='BASE TABLE' AND TABLE_SCHEMA='$_ '"
6724
- );
6725
- infoprint " +-- TABLE : $nbTables " ;
6733
+ );
6734
+ infoprint " +-- TABLE : $nbTables " ;
6726
6735
infoprint " +-- VIEW : "
6727
6736
. select_one(
6728
6737
" SELECT count(*) from information_schema.TABLES WHERE TABLE_TYPE ='VIEW' AND TABLE_SCHEMA='$_ '"
@@ -6778,10 +6787,10 @@ sub mysql_databases {
6778
6787
) . " TABLE(s)" ;
6779
6788
}
6780
6789
6781
- if ( $nbTables == 0 ) {
6782
- badprint " No table in $dbinfo [0] database" ;
6783
- next ;
6784
- }
6790
+ if ( $nbTables == 0 ) {
6791
+ badprint " No table in $dbinfo [0] database" ;
6792
+ next ;
6793
+ }
6785
6794
badprint " Index size is larger than data size for $dbinfo [0] \n "
6786
6795
if ( $dbinfo [2] ne ' NULL' )
6787
6796
and ( $dbinfo [3] ne ' NULL' )
@@ -6792,7 +6801,7 @@ sub mysql_databases {
6792
6801
. " storage engines. Be careful. \n " ;
6793
6802
push @generalrec ,
6794
6803
" Select one storage engine (InnoDB is a good choice) for all tables in $dbinfo [0] database ($dbinfo [5] engines detected)" ;
6795
- }
6804
+ }
6796
6805
$result {' Databases' }{ $dbinfo [0] }{' Rows' } = $dbinfo [1];
6797
6806
$result {' Databases' }{ $dbinfo [0] }{' Tables' } = $dbinfo [6];
6798
6807
$result {' Databases' }{ $dbinfo [0] }{' Collations' } = $dbinfo [7];
@@ -7096,12 +7105,13 @@ sub mysql_indexes {
7096
7105
infoprint " +-- COMMENT : " . $info [5] if defined $info [5];
7097
7106
$found ++;
7098
7107
}
7099
- my $nbTables = select_one(
7108
+ my $nbTables = select_one(
7100
7109
" SELECT count(*) from information_schema.TABLES WHERE TABLE_TYPE ='BASE TABLE' AND TABLE_SCHEMA='$dbname '"
7101
- );
7102
- 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;
7103
7113
push @generalrec , " Add indexes on tables from $dbname database"
7104
- if $found == 0 and $nbTables > 1;
7114
+ if $found == 0 and $nbTables > 1;
7105
7115
}
7106
7116
return
7107
7117
unless ( defined ( $myvar {' performance_schema' } )
0 commit comments