From 96fbedff7280e8d4a7ca8ccb76047003ab7abefb Mon Sep 17 00:00:00 2001 From: Jean-Marie Renouard Date: Tue, 25 Apr 2023 23:05:47 +0200 Subject: [PATCH 1/7] Adding stop after dumping option --- mysqltuner.pl | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/mysqltuner.pl b/mysqltuner.pl index 765aea2..b9d27a5 100644 --- a/mysqltuner.pl +++ b/mysqltuner.pl @@ -111,6 +111,7 @@ my %opt = ( "defaults-extra-file" => '', "protocol" => '', "dumpdir" => '', + "stop-after-dumping" => 0, ); # Gather the options from the command line @@ -143,6 +144,7 @@ GetOptions( 'idxstat', 'noidxstat', 'server-log=s', 'protocol=s', 'defaults-extra-file=s', 'dumpdir=s', + 'stop-after-dumping' ) or pod2usage( -exitval => 1, @@ -1035,17 +1037,35 @@ sub select_array { return @result; } +# MySQL Request Array +sub select_array_with_headers { + my $req = shift; + debugprint "PERFORM: $req "; + my @result = `$mysqlcmd $mysqllogin -Bs --column-name -e "\\w$req" 2>>/dev/null`; + if ( $? != 0 ) { + badprint "Failed to execute: $req"; + badprint "FAIL Execute SQL / return code: $?"; + debugprint "CMD : $mysqlcmd"; + debugprint "OPTIONS: $mysqllogin"; + debugprint `$mysqlcmd $mysqllogin -Bse "$req" 2>&1`; + + #exit $?; + } + debugprint "select_array: return code : $?"; + chomp(@result); + return @result; +} # MySQL Request Array sub select_csv_file { my $tfile = shift; my $req = shift; debugprint "PERFORM: $req CSV into $tfile"; - my @result = select_array($req); + my @result = select_array_with_headers($req); open( my $fh, '>', $tfile ) or die "Could not open file '$tfile' $!"; for my $l (@result) { $l =~ s/\t/","/g; $l =~ s/^/"/; - $l =~ s/$/"/; + $l =~ s/$/"\n/; print $fh $l; } close $fh; @@ -2653,6 +2673,7 @@ sub calculations { exit 2; } + # Per-thread memory # Per-thread memory if ( mysql_version_ge(4) ) { $mycalc{'per_thread_buffers'} = @@ -3951,6 +3972,7 @@ sub mysqsl_pfs { ); } } + exit 0 if ( $opt{stop-after-dumping} == 1 ); # Top user per connection subheaderprint "Performance schema: Top 5 user per connection"; From b218cdf05fa26735e9404b827fe56028cb5f8ccf Mon Sep 17 00:00:00 2001 From: Jean-Marie Renouard Date: Tue, 25 Apr 2023 23:43:23 +0200 Subject: [PATCH 2/7] Adding stop option into mysql_tables --- mysqltuner.pl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mysqltuner.pl b/mysqltuner.pl index 8c5a078..43dae64 100644 --- a/mysqltuner.pl +++ b/mysqltuner.pl @@ -111,7 +111,7 @@ my %opt = ( "defaults-extra-file" => '', "protocol" => '', "dumpdir" => '', - "stop-after-dumping" => 0, + "stop" => 0, ); # Gather the options from the command line @@ -144,7 +144,7 @@ GetOptions( 'idxstat', 'noidxstat', 'server-log=s', 'protocol=s', 'defaults-extra-file=s', 'dumpdir=s', - 'stop-after-dumping' + 'stop' ) or pod2usage( -exitval => 1, @@ -3972,7 +3972,7 @@ sub mysqsl_pfs { ); } } - exit 0 if ( $opt{stop-after-dumping} == 1 ); + exit 0 if ( $opt{stop} == 1 ); # Top user per connection subheaderprint "Performance schema: Top 5 user per connection"; @@ -6508,6 +6508,7 @@ sub mysql_tables { "select * from information_schema.$info_s_table" ); } + exit 0 if ( $opt{stop} == 1 ); } foreach ( select_user_dbs() ) { my $dbname = $_; From c825e7d66ba3443ae2b5b6d25abc4f21ad25a16d Mon Sep 17 00:00:00 2001 From: Jean-Marie Renouard Date: Wed, 26 Apr 2023 00:05:23 +0200 Subject: [PATCH 3/7] add stop in a other place --- mysqltuner.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/mysqltuner.pl b/mysqltuner.pl index 43dae64..e6d2ce0 100644 --- a/mysqltuner.pl +++ b/mysqltuner.pl @@ -6510,6 +6510,7 @@ sub mysql_tables { } exit 0 if ( $opt{stop} == 1 ); } + exit 0 if ( $opt{stop} == 1 ); foreach ( select_user_dbs() ) { my $dbname = $_; next unless defined $_; From f9debbf20d8efdbc82fb252a5fd3e8fcddcdfe1c Mon Sep 17 00:00:00 2001 From: Jean-Marie Renouard Date: Wed, 26 Apr 2023 00:14:12 +0200 Subject: [PATCH 4/7] Adding info message --- mysqltuner.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/mysqltuner.pl b/mysqltuner.pl index e6d2ce0..3a5ad12 100644 --- a/mysqltuner.pl +++ b/mysqltuner.pl @@ -6497,6 +6497,7 @@ sub mysql_tables { } + infoprint("Dumpdir: $opt{dumpdir}"); # Store all information schema in dumpdir if defined if ( defined $opt{dumpdir} and -d "$opt{dumpdir}" ) { for my $info_s_table ( From bd9d921ae8c6bd742c7d3e3caed3017fea73febb Mon Sep 17 00:00:00 2001 From: Jean-Marie Renouard Date: Wed, 26 Apr 2023 00:29:41 +0200 Subject: [PATCH 5/7] Adding debug info --- mysqltuner.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/mysqltuner.pl b/mysqltuner.pl index 3a5ad12..74e8af1 100644 --- a/mysqltuner.pl +++ b/mysqltuner.pl @@ -1046,6 +1046,7 @@ sub select_array_with_headers { badprint "Failed to execute: $req"; badprint "FAIL Execute SQL / return code: $?"; debugprint "CMD : $mysqlcmd"; + debugprint "COMMAND: $mysqlcmd"; debugprint "OPTIONS: $mysqllogin"; debugprint `$mysqlcmd $mysqllogin -Bse "$req" 2>&1`; From 7b385a95186b3891fc40688c5e930ec0b047d751 Mon Sep 17 00:00:00 2001 From: Jean-Marie Renouard Date: Wed, 26 Apr 2023 00:49:53 +0200 Subject: [PATCH 6/7] new test for exporting CSV with headers --- mysqltuner.pl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mysqltuner.pl b/mysqltuner.pl index 74e8af1..f431dec 100644 --- a/mysqltuner.pl +++ b/mysqltuner.pl @@ -1041,18 +1041,17 @@ sub select_array { sub select_array_with_headers { my $req = shift; debugprint "PERFORM: $req "; - my @result = `$mysqlcmd $mysqllogin -Bs --column-name -e "\\w$req" 2>>/dev/null`; + my @result = `$mysqlcmd $mysqllogin -Bre "\\w$req" 2>>/dev/null`; if ( $? != 0 ) { badprint "Failed to execute: $req"; badprint "FAIL Execute SQL / return code: $?"; debugprint "CMD : $mysqlcmd"; - debugprint "COMMAND: $mysqlcmd"; debugprint "OPTIONS: $mysqllogin"; debugprint `$mysqlcmd $mysqllogin -Bse "$req" 2>&1`; #exit $?; } - debugprint "select_array: return code : $?"; + debugprint "select_array_with_headers: return code : $?"; chomp(@result); return @result; } From 5ac9844030e613eb728f86837175fb9362ed9b4c Mon Sep 17 00:00:00 2001 From: Jean-Marie Renouard Date: Wed, 26 Apr 2023 00:54:23 +0200 Subject: [PATCH 7/7] debug with csv lines --- mysqltuner.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/mysqltuner.pl b/mysqltuner.pl index f431dec..85be3d2 100644 --- a/mysqltuner.pl +++ b/mysqltuner.pl @@ -1067,6 +1067,7 @@ sub select_csv_file { $l =~ s/^/"/; $l =~ s/$/"\n/; print $fh $l; + print $l if $opt{debug}; } close $fh; }