Skip to content

Commit 2f926c8

Browse files
authored
Merge pull request #853 from jmrenouard/master
wsrep_slave_threads deprecated in mySQL 8.0+ #819
2 parents 60e2aa5 + 62f2b03 commit 2f926c8

File tree

6 files changed

+137
-100
lines changed

6 files changed

+137
-100
lines changed

README.fr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![MySQLTuner-perl](https://github.com/major/MySQLTuner-perl/blob/master/mtlogo.png)
1+
![MySQLTuner-perl](mtlogo2.png)
22

33
[!["Buy Us A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/jmrenouard)
44

README.it.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![MySQLTuner-perl](https://github.com/major/MySQLTuner-perl/blob/master/mtlogo.png)
1+
![MySQLTuner-perl](mtlogo2.png)
22

33
[!["Buy Us A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/jmrenouard)
44

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![MySQLTuner-perl](https://github.com/major/MySQLTuner-perl/blob/master/mtlogo.png)
1+
![MySQLTuner-perl](mtlogo2.png)
22

33
[!["Buy Us A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/jmrenouard)
44

README.ru.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![MySQLTuner-perl](https://github.com/major/MySQLTuner-perl/blob/master/mtlogo.png)
1+
![MySQLTuner-perl](mtlogo2.png)
22

33
[!["Buy Us A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/jmrenouard)
44

mtlogo2.png

224 KB
Loading

mysqltuner.pl

Lines changed: 133 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,9 @@ sub hr_bytes_practical_rnd {
446446
my $num = shift;
447447
return "0B" unless defined($num) and $num > 0;
448448

449-
my $gbs = $num / (1024**3); # convert to GB
449+
my $gbs = $num / ( 1024**3 ); # convert to GB
450450
my $power_of_2_gb = 1;
451-
while ($power_of_2_gb < $gbs) {
451+
while ( $power_of_2_gb < $gbs ) {
452452
$power_of_2_gb *= 2;
453453
}
454454

@@ -2253,10 +2253,6 @@ sub security_recommendations {
22532253
subheaderprint "Security Recommendations";
22542254

22552255
infoprint "$myvar{'version_comment'} - $myvar{'version'}";
2256-
if ( mysql_version_ge(8.0) ) {
2257-
infoprint "Skipped due to unsupported feature for MySQL 8.0+";
2258-
return;
2259-
}
22602256

22612257
#exit 0;
22622258
if ( $opt{skippassword} eq 1 ) {
@@ -2377,15 +2373,17 @@ sub security_recommendations {
23772373
}
23782374

23792375
# Looking for User with user/ uppercase /capitalise user as password
2380-
@mysqlstatlist = select_array
2376+
if ( !mysql_version_ge(8) ) {
2377+
@mysqlstatlist = select_array
23812378
"SELECT CONCAT(QUOTE(user), '\@', QUOTE(host)) FROM mysql.user WHERE user != '' AND (CAST($PASS_COLUMN_NAME as Binary) = PASSWORD(user) OR CAST($PASS_COLUMN_NAME as Binary) = PASSWORD(UPPER(user)) OR CAST($PASS_COLUMN_NAME as Binary) = PASSWORD(CONCAT(UPPER(LEFT(User, 1)), SUBSTRING(User, 2, LENGTH(User)))))";
2382-
if (@mysqlstatlist) {
2383-
foreach my $line ( sort @mysqlstatlist ) {
2384-
chomp($line);
2385-
badprint "User " . $line . " has user name as password.";
2386-
push( @generalrec,
2379+
if (@mysqlstatlist) {
2380+
foreach my $line ( sort @mysqlstatlist ) {
2381+
chomp($line);
2382+
badprint "User " . $line . " has user name as password.";
2383+
push( @generalrec,
23872384
"Set up a Secure Password for $line user: SET PASSWORD FOR $line = PASSWORD('secure_password');"
2388-
);
2385+
);
2386+
}
23892387
}
23902388
}
23912389

@@ -2419,44 +2417,46 @@ sub security_recommendations {
24192417
my $nbins = 0;
24202418
my $passreq;
24212419
if (@passwords) {
2422-
my $nbInterPass = 0;
2423-
foreach my $pass (@passwords) {
2424-
$nbInterPass++;
2425-
2426-
$pass =~ s/\s//g;
2427-
$pass =~ s/\'/\\\'/g;
2428-
chomp($pass);
2429-
2430-
# Looking for User with user/ uppercase /capitalise weak password
2431-
@mysqlstatlist =
2432-
select_array
2420+
if ( !mysql_version_ge(8) ) {
2421+
my $nbInterPass = 0;
2422+
foreach my $pass (@passwords) {
2423+
$nbInterPass++;
2424+
2425+
$pass =~ s/\s//g;
2426+
$pass =~ s/\'/\\\'/g;
2427+
chomp($pass);
2428+
2429+
# Looking for User with user/ uppercase /capitalise weak password
2430+
@mysqlstatlist =
2431+
select_array
24332432
"SELECT CONCAT(user, '\@', host) FROM mysql.user WHERE $PASS_COLUMN_NAME = PASSWORD('"
2434-
. $pass
2435-
. "') OR $PASS_COLUMN_NAME = PASSWORD(UPPER('"
2436-
. $pass
2437-
. "')) OR $PASS_COLUMN_NAME = PASSWORD(CONCAT(UPPER(LEFT('"
2438-
. $pass
2439-
. "', 1)), SUBSTRING('"
2440-
. $pass
2441-
. "', 2, LENGTH('"
2442-
. $pass . "'))))";
2443-
debugprint "There are " . scalar(@mysqlstatlist) . " items.";
2444-
if (@mysqlstatlist) {
2445-
foreach my $line (@mysqlstatlist) {
2446-
chomp($line);
2447-
badprint "User '" . $line
2448-
. "' is using weak password: $pass in a lower, upper or capitalize derivative version.";
2433+
. $pass
2434+
. "') OR $PASS_COLUMN_NAME = PASSWORD(UPPER('"
2435+
. $pass
2436+
. "')) OR $PASS_COLUMN_NAME = PASSWORD(CONCAT(UPPER(LEFT('"
2437+
. $pass
2438+
. "', 1)), SUBSTRING('"
2439+
. $pass
2440+
. "', 2, LENGTH('"
2441+
. $pass . "'))))";
2442+
debugprint "There are " . scalar(@mysqlstatlist) . " items.";
2443+
if (@mysqlstatlist) {
2444+
foreach my $line (@mysqlstatlist) {
2445+
chomp($line);
2446+
badprint "User '" . $line
2447+
. "' is using weak password: $pass in a lower, upper or capitalize derivative version.";
24492448

2450-
push( @generalrec,
2449+
push( @generalrec,
24512450
"Set up a Secure Password for $line user: SET PASSWORD FOR '"
2452-
. ( split /@/, $line )[0] . "'\@'"
2453-
. ( split /@/, $line )[1]
2454-
. "' = PASSWORD('secure_password');" );
2455-
$nbins++;
2451+
. ( split /@/, $line )[0] . "'\@'"
2452+
. ( split /@/, $line )[1]
2453+
. "' = PASSWORD('secure_password');" );
2454+
$nbins++;
2455+
}
24562456
}
2457+
debugprint "$nbInterPass / " . scalar(@passwords)
2458+
if ( $nbInterPass % 1000 == 0 );
24572459
}
2458-
debugprint "$nbInterPass / " . scalar(@passwords)
2459-
if ( $nbInterPass % 1000 == 0 );
24602460
}
24612461
}
24622462
if ( $nbins > 0 ) {
@@ -5996,9 +5996,7 @@ sub trim {
59965996
sub get_wsrep_options {
59975997
return () unless defined $myvar{'wsrep_provider_options'};
59985998

5999-
my @galera_options = split /;/, $myvar{'wsrep_provider_options'};
6000-
my $wsrep_slave_threads = $myvar{'wsrep_slave_threads'};
6001-
push @galera_options, ' wsrep_slave_threads = ' . $wsrep_slave_threads;
5999+
my @galera_options = split /;/, $myvar{'wsrep_provider_options'};
60026000
@galera_options = remove_cr @galera_options;
60036001
@galera_options = remove_empty @galera_options;
60046002

@@ -6176,25 +6174,33 @@ sub mariadb_galera {
61766174
. hr_bytes_rnd( get_wsrep_option('gcache.mem_size') );
61776175

61786176
infoprint "CPU cores detected : " . (cpu_cores);
6179-
infoprint "wsrep_slave_threads: " . get_wsrep_option('wsrep_slave_threads');
6177+
my $wsrep_threads_var_name = 'wsrep_slave_threads';
6178+
if ( defined( $myvar{'wsrep_applier_threads'} ) ) {
6179+
$wsrep_threads_var_name = 'wsrep_applier_threads';
6180+
}
6181+
# Use 1 as a fallback if $myvar{$wsrep_threads_var_name} is undefined or zero,
6182+
# to ensure there is at least one thread for Galera replication.
6183+
my $wsrep_threads_value = $myvar{$wsrep_threads_var_name} || 1;
6184+
6185+
infoprint "$wsrep_threads_var_name: " . $wsrep_threads_value;
61806186

6181-
if ( get_wsrep_option('wsrep_slave_threads') > ( (cpu_cores) * 4 )
6182-
or get_wsrep_option('wsrep_slave_threads') < ( (cpu_cores) * 2 ) )
6187+
if ( $wsrep_threads_value > ( (cpu_cores) * 4 )
6188+
or $wsrep_threads_value < ( (cpu_cores) * 2 ) )
61836189
{
61846190
badprint
6185-
"wsrep_slave_threads is not equal to 2, 3 or 4 times the number of CPU(s)";
6186-
push @adjvars, "wsrep_slave_threads = " . ( (cpu_cores) * 4 );
6191+
"$wsrep_threads_var_name is not equal to 2, 3 or 4 times the number of CPU(s)";
6192+
push @adjvars, "$wsrep_threads_var_name = " . ( (cpu_cores) * 4 );
61876193
}
61886194
else {
61896195
goodprint
6190-
"wsrep_slave_threads is equal to 2, 3 or 4 times the number of CPU(s)";
6196+
"$wsrep_threads_var_name is equal to 2, 3 or 4 times the number of CPU(s)";
61916197
}
61926198

6193-
if ( get_wsrep_option('wsrep_slave_threads') > 1 ) {
6199+
if ( $wsrep_threads_value > 1 ) {
61946200
infoprint
61956201
"wsrep parallel slave can cause frequent inconsistency crash.";
61966202
push @adjvars,
6197-
"Set wsrep_slave_threads to 1 in case of HA_ERR_FOUND_DUPP_KEY crash on slave";
6203+
"Set $wsrep_threads_var_name to 1 in case of HA_ERR_FOUND_DUPP_KEY crash on slave";
61986204

61996205
# check options for parallel slave
62006206
if ( get_wsrep_option('wsrep_slave_FK_checks') eq "OFF" ) {
@@ -6212,15 +6218,15 @@ sub mariadb_galera {
62126218
}
62136219
}
62146220

6215-
if ( get_wsrep_option('gcs.fc_limit') != $myvar{'wsrep_slave_threads'} * 5 )
6216-
{
6217-
badprint "gcs.fc_limit should be equal to 5 * wsrep_slave_threads (="
6218-
. ( $myvar{'wsrep_slave_threads'} * 5 ) . ")";
6219-
push @adjvars, "gcs.fc_limit= wsrep_slave_threads * 5 (="
6220-
. ( $myvar{'wsrep_slave_threads'} * 5 ) . ")";
6221+
if ( get_wsrep_option('gcs.fc_limit') != $wsrep_threads_value * 5 ) {
6222+
badprint
6223+
"gcs.fc_limit should be equal to 5 * $wsrep_threads_var_name (="
6224+
. ( $wsrep_threads_value * 5 ) . ")";
6225+
push @adjvars, "gcs.fc_limit= $wsrep_threads_var_name * 5 (="
6226+
. ( $wsrep_threads_value * 5 ) . ")";
62216227
}
62226228
else {
6223-
goodprint "gcs.fc_limit is equal to 5 * wsrep_slave_threads ( ="
6229+
goodprint "gcs.fc_limit is equal to 5 * $wsrep_threads_var_name ( ="
62246230
. get_wsrep_option('gcs.fc_limit') . ")";
62256231
}
62266232

@@ -6595,39 +6601,60 @@ sub mysql_innodb {
65956601
}
65966602
}
65976603
}
6598-
# InnoDB Log File Size / InnoDB Redo Log Capacity Recommendations
6599-
# For MySQL < 8.0.30, the recommendation is based on innodb_log_file_size and innodb_log_files_in_group.
6600-
# For MySQL >= 8.0.30, innodb_redo_log_capacity replaces the old system.
6601-
if ( mysql_version_ge( 8, 0, 30 ) && defined $myvar{'innodb_redo_log_capacity'} ) {
6604+
6605+
# InnoDB Log File Size / InnoDB Redo Log Capacity Recommendations
6606+
# For MySQL < 8.0.30, the recommendation is based on innodb_log_file_size and innodb_log_files_in_group.
6607+
# For MySQL >= 8.0.30, innodb_redo_log_capacity replaces the old system.
6608+
if ( mysql_version_ge( 8, 0, 30 )
6609+
&& defined $myvar{'innodb_redo_log_capacity'} )
6610+
{
66026611
# New recommendation logic for MySQL >= 8.0.30
6603-
infoprint "InnoDB Redo Log Capacity is set to " . hr_bytes($myvar{'innodb_redo_log_capacity'});
6612+
infoprint "InnoDB Redo Log Capacity is set to "
6613+
. hr_bytes( $myvar{'innodb_redo_log_capacity'} );
66046614

66056615
my $innodb_os_log_written = $mystat{'Innodb_os_log_written'} || 0;
6606-
my $uptime = $mystat{'Uptime'} || 1;
6616+
my $uptime = $mystat{'Uptime'} || 1;
66076617

6608-
if ($uptime > 3600) { # Only make a recommendation if server has been up for at least an hour
6618+
if ( $uptime > 3600 )
6619+
{ # Only make a recommendation if server has been up for at least an hour
66096620
my $hourly_rate = $innodb_os_log_written / ( $uptime / 3600 );
6610-
my $suggested_redo_log_capacity_str = hr_bytes_practical_rnd($hourly_rate);
6611-
my $suggested_redo_log_capacity_bytes = hr_raw($suggested_redo_log_capacity_str);
6621+
my $suggested_redo_log_capacity_str =
6622+
hr_bytes_practical_rnd($hourly_rate);
6623+
my $suggested_redo_log_capacity_bytes =
6624+
hr_raw($suggested_redo_log_capacity_str);
66126625

6613-
infoprint "Hourly InnoDB log write rate: " . hr_bytes_rnd($hourly_rate) . "/hour";
6626+
infoprint "Hourly InnoDB log write rate: "
6627+
. hr_bytes_rnd($hourly_rate) . "/hour";
66146628

6615-
if (hr_raw($myvar{'innodb_redo_log_capacity'}) < $hourly_rate) {
6616-
badprint "Your innodb_redo_log_capacity is not large enough to hold at least 1 hour of writes.";
6617-
push( @adjvars, "innodb_redo_log_capacity (>= " . $suggested_redo_log_capacity_str . ")" );
6618-
} else {
6619-
goodprint "Your innodb_redo_log_capacity is sized to handle more than 1 hour of writes.";
6629+
if ( hr_raw( $myvar{'innodb_redo_log_capacity'} ) < $hourly_rate ) {
6630+
badprint
6631+
"Your innodb_redo_log_capacity is not large enough to hold at least 1 hour of writes.";
6632+
push( @adjvars,
6633+
"innodb_redo_log_capacity (>= "
6634+
. $suggested_redo_log_capacity_str
6635+
. ")" );
6636+
}
6637+
else {
6638+
goodprint
6639+
"Your innodb_redo_log_capacity is sized to handle more than 1 hour of writes.";
66206640
}
66216641

66226642
# Sanity check against total InnoDB data size
6623-
if ( defined $enginestats{'InnoDB'} and $enginestats{'InnoDB'} > 0 ) {
6643+
if ( defined $enginestats{'InnoDB'} and $enginestats{'InnoDB'} > 0 )
6644+
{
66246645
my $total_innodb_size = $enginestats{'InnoDB'};
6625-
if ( $suggested_redo_log_capacity_bytes > $total_innodb_size * 0.25 ) {
6626-
infoprint "The suggested innodb_redo_log_capacity (" . $suggested_redo_log_capacity_str . ") is more than 25% of your total InnoDB data size. This might be unnecessarily large.";
6646+
if ( $suggested_redo_log_capacity_bytes >
6647+
$total_innodb_size * 0.25 )
6648+
{
6649+
infoprint "The suggested innodb_redo_log_capacity ("
6650+
. $suggested_redo_log_capacity_str
6651+
. ") is more than 25% of your total InnoDB data size. This might be unnecessarily large.";
66276652
}
66286653
}
6629-
} else {
6630-
infoprint "Server uptime is less than 1 hour. Cannot make a reliable recommendation for innodb_redo_log_capacity.";
6654+
}
6655+
else {
6656+
infoprint
6657+
"Server uptime is less than 1 hour. Cannot make a reliable recommendation for innodb_redo_log_capacity.";
66316658
}
66326659
}
66336660
else {
@@ -6648,11 +6675,12 @@ sub mysql_innodb {
66486675
. ") if possible, so InnoDB Redo log Capacity equals 25% of buffer pool size."
66496676
);
66506677
push( @generalrec,
6651-
"Be careful, increasing innodb_redo_log_capacity means higher crash recovery mean time"
6678+
"Be careful, increasing innodb_redo_log_capacity means higher crash recovery mean time"
66526679
);
66536680
}
66546681
else {
6655-
badprint "Ratio InnoDB log file size / InnoDB Buffer pool size ("
6682+
badprint
6683+
"Ratio InnoDB log file size / InnoDB Buffer pool size ("
66566684
. $mycalc{'innodb_log_size_pct'} . "%): "
66576685
. hr_bytes( $myvar{'innodb_log_file_size'} ) . " * "
66586686
. $myvar{'innodb_log_files_in_group'} . " / "
@@ -6678,12 +6706,12 @@ sub mysql_innodb {
66786706
. ") if possible, so InnoDB total log file size equals 25% of buffer pool size."
66796707
);
66806708
push( @generalrec,
6681-
"Be careful, increasing innodb_log_file_size / innodb_log_files_in_group means higher crash recovery mean time"
6709+
"Be careful, increasing innodb_log_file_size / innodb_log_files_in_group means higher crash recovery mean time"
66826710
);
66836711
}
66846712
if ( mysql_version_le( 5, 6, 2 ) ) {
66856713
push( @generalrec,
6686-
"For MySQL 5.6.2 and lower, total innodb_log_file_size should have a ceiling of (4096MB / log files in group) - 1MB."
6714+
"For MySQL 5.6.2 and lower, total innodb_log_file_size should have a ceiling of (4096MB / log files in group) - 1MB."
66876715
);
66886716
}
66896717
}
@@ -6697,9 +6725,10 @@ sub mysql_innodb {
66976725
}
66986726
else {
66996727
push( @generalrec,
6700-
"Before changing innodb_log_file_size and/or innodb_log_files_in_group read this: https://bit.ly/2TcGgtU"
6728+
"Before changing innodb_log_file_size and/or innodb_log_files_in_group read this: https://bit.ly/2TcGgtU"
67016729
);
6702-
goodprint "Ratio InnoDB log file size / InnoDB Buffer pool size: "
6730+
goodprint
6731+
"Ratio InnoDB log file size / InnoDB Buffer pool size: "
67036732
. hr_bytes( $myvar{'innodb_log_file_size'} ) . " * "
67046733
. $myvar{'innodb_log_files_in_group'} . "/"
67056734
. hr_bytes( $myvar{'innodb_buffer_pool_size'} )
@@ -6762,10 +6791,14 @@ sub mysql_innodb {
67626791
}
67636792

67646793
# InnoDB Used Buffer Pool Size vs CHUNK size
6765-
if ( $myvar{'version'} =~ /MariaDB/i and mysql_version_ge(10, 8) and $myvar{'innodb_buffer_pool_chunk_size'} == 0) {
6766-
infoprint "innodb_buffer_pool_chunk_size is set to 'autosize' (0) in MariaDB >= 10.8. Skipping chunk size checks.";
6794+
if ( $myvar{'version'} =~ /MariaDB/i
6795+
and mysql_version_ge( 10, 8 )
6796+
and $myvar{'innodb_buffer_pool_chunk_size'} == 0 )
6797+
{
6798+
infoprint
6799+
"innodb_buffer_pool_chunk_size is set to 'autosize' (0) in MariaDB >= 10.8. Skipping chunk size checks.";
67676800
}
6768-
elsif ( !defined( $myvar{'innodb_buffer_pool_chunk_size'} )
6801+
elsif (!defined( $myvar{'innodb_buffer_pool_chunk_size'} )
67696802
|| $myvar{'innodb_buffer_pool_chunk_size'} == 0
67706803
|| !defined( $myvar{'innodb_buffer_pool_size'} )
67716804
|| $myvar{'innodb_buffer_pool_size'} == 0
@@ -6821,8 +6854,11 @@ sub mysql_innodb {
68216854
}
68226855

68236856
# InnoDB Read efficiency
6824-
if ( $mystat{'Innodb_buffer_pool_reads'} > $mystat{'Innodb_buffer_pool_read_requests'} ) {
6825-
infoprint "InnoDB Read buffer efficiency: metrics are not reliable (reads > read requests)";
6857+
if ( $mystat{'Innodb_buffer_pool_reads'} >
6858+
$mystat{'Innodb_buffer_pool_read_requests'} )
6859+
{
6860+
infoprint
6861+
"InnoDB Read buffer efficiency: metrics are not reliable (reads > read requests)";
68266862
}
68276863
elsif ( defined $mycalc{'pct_read_efficiency'}
68286864
&& $mycalc{'pct_read_efficiency'} < 90 )
@@ -6847,7 +6883,8 @@ sub mysql_innodb {
68476883

68486884
# InnoDB Write efficiency
68496885
if ( $mystat{'Innodb_log_writes'} > $mystat{'Innodb_log_write_requests'} ) {
6850-
infoprint "InnoDB Write Log efficiency: metrics are not reliable (writes > write requests)";
6886+
infoprint
6887+
"InnoDB Write Log efficiency: metrics are not reliable (writes > write requests)";
68516888
}
68526889
elsif ( defined $mycalc{'pct_write_efficiency'}
68536890
&& $mycalc{'pct_write_efficiency'} < 90 )

0 commit comments

Comments
 (0)