From 183aac3f4a83d9886ecddf3889cfb3cdd6aafa98 Mon Sep 17 00:00:00 2001 From: Jean-Marie Renouard Date: Thu, 22 Jun 2023 21:45:07 +0200 Subject: [PATCH 1/7] adding generic function dump_into_file --- mysqltuner.pl | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/mysqltuner.pl b/mysqltuner.pl index fcd6a22..b8a6f09 100644 --- a/mysqltuner.pl +++ b/mysqltuner.pl @@ -2750,6 +2750,17 @@ sub check_storage_engines { my %mycalc; +sub dump_into_file { + my $file=shift; + my $content=shift; + if ( -d "$opt{dumpdir}" ) { + $file="$opt{dumpdir}/$file"; + open (FILE, ">$file") or die "Can't open $file: $!"; + print FILE $content; + close FILE; + infoprint "Data saved to $file"; + } +} sub calculations { if ( $mystat{'Questions'} < 1 ) { badprint "Your server has not answered any queries: cannot continue..."; @@ -3790,13 +3801,7 @@ sub mysql_myisam { $sql_mig="${sql_mig}-- InnoDB migration for $myisam_table\nALTER TABLE $myisam_table ENGINE=InnoDB;\n\n"; infoprint "* InnoDB migration request for $myisam_table Table: ALTER TABLE $myisam_table ENGINE=InnoDB;"; } - if ( -d "$opt{dumpdir}" ) { - my $file_mig="$opt{dumpdir}/migrate_myisam_to_innodb.sql"; - open (FILE, ">$file_mig") or die "Can't open $file_mig: $!"; - print FILE $sql_mig; - close FILE; - infoprint "Migration script saved to $file_mig"; - } + dump_into_file("migrate_myisam_to_innodb.sql", $sql_mig ); } infoprint("General MyIsam metrics:"); infoprint " +-- Total MyISAM Tables : $nb_myisam_tables"; From 7bbc6db3e770f7227b8b25792e666580d4b45178 Mon Sep 17 00:00:00 2001 From: Jean-Marie Renouard Date: Thu, 22 Jun 2023 22:11:10 +0200 Subject: [PATCH 2/7] add new badge --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e8afe97..927733f 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,13 @@ [!["Buy Us A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/jmrenouard) -[![Build Status - Master](https://travis-ci.org/major/MySQLTuner-perl.svg?branch=master)](https://travis-ci.org/major/MySQLTuner-perl) +

+ + Tests Passing + + [![Project Status](http://opensource.box.com/badges/active.svg)](http://opensource.box.com/badges) +[![Test Status](https://github.com/anuraghazra/github-readme-stats/workflows/Test/badge.svg)](https://github.com/anuraghazra/github-readme-stats/workflows/Test/badge.svg) [![Project Status](http://opensource.box.com/badges/maintenance.svg)](http://opensource.box.com/badges) [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/major/MySQLTuner-perl.svg)](http://isitmaintained.com/project/major/MySQLTuner-perl "Average time to resolve an issue") [![Percentage of open issues](http://isitmaintained.com/badge/open/major/MySQLTuner-perl.svg)](http://isitmaintained.com/project/major/MySQLTuner-perl "Percentage of issues still open") @@ -28,8 +33,11 @@ MySQLTuner needs you * Please join us on issue track at [GitHub tracker](https://github.com/major/MySQLTuner-perl/issues). * Contribution guide is available following [MySQLTuner contributing guide](https://github.com/major/MySQLTuner-perl/blob/master/CONTRIBUTING.md) * Star **MySQLTuner project** at [MySQLTuner Git Hub Project](https://github.com/major/MySQLTuner-perl) +* Paid support for LightPath here: [jmrenouard@lightpath.fr](jmrenouard@lightpath.fr) * Paid support for Releem available here: [Releem App](https://releem.com/) +![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&theme=radical) + ## Stargazers over time [![Stargazers over time](https://starcharts.herokuapp.com/major/MySQLTuner-perl.svg)](https://starcharts.herokuapp.com/major/MySQLTuner-perl) From 5a0530219edc851b50d313e30c6fb69ec6b44014 Mon Sep 17 00:00:00 2001 From: Jean-Marie Renouard Date: Thu, 22 Jun 2023 22:12:15 +0200 Subject: [PATCH 3/7] add badges --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 927733f..2fc8692 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![Project Status](http://opensource.box.com/badges/active.svg)](http://opensource.box.com/badges) -[![Test Status](https://github.com/anuraghazra/github-readme-stats/workflows/Test/badge.svg)](https://github.com/anuraghazra/github-readme-stats/workflows/Test/badge.svg) +[![Test Status](https://github.com/anuraghazra/github-readme-stats/workflows/Test/badge.svg)](https://github.com/anuraghazra/github-readme-stats/) [![Project Status](http://opensource.box.com/badges/maintenance.svg)](http://opensource.box.com/badges) [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/major/MySQLTuner-perl.svg)](http://isitmaintained.com/project/major/MySQLTuner-perl "Average time to resolve an issue") [![Percentage of open issues](http://isitmaintained.com/badge/open/major/MySQLTuner-perl.svg)](http://isitmaintained.com/project/major/MySQLTuner-perl "Percentage of issues still open") From af3dda7e42618c880a664692ce5907387983e746 Mon Sep 17 00:00:00 2001 From: Jean-Marie Renouard Date: Thu, 22 Jun 2023 22:13:41 +0200 Subject: [PATCH 4/7] reorder icons --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 2fc8692..f497563 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ [![Project Status](http://opensource.box.com/badges/active.svg)](http://opensource.box.com/badges) [![Test Status](https://github.com/anuraghazra/github-readme-stats/workflows/Test/badge.svg)](https://github.com/anuraghazra/github-readme-stats/) -[![Project Status](http://opensource.box.com/badges/maintenance.svg)](http://opensource.box.com/badges) [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/major/MySQLTuner-perl.svg)](http://isitmaintained.com/project/major/MySQLTuner-perl "Average time to resolve an issue") [![Percentage of open issues](http://isitmaintained.com/badge/open/major/MySQLTuner-perl.svg)](http://isitmaintained.com/project/major/MySQLTuner-perl "Percentage of issues still open") [![GPL License](https://badges.frapsoft.com/os/gpl/gpl.png?v=103)](https://opensource.org/licenses/GPL-3.0/) From 218534054847492bef43c2cb06e1ac738e6754fd Mon Sep 17 00:00:00 2001 From: Jean-Marie Renouard Date: Thu, 22 Jun 2023 22:14:14 +0200 Subject: [PATCH 5/7] remove badges --- README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.md b/README.md index f497563..2659f0a 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,6 @@ [!["Buy Us A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/jmrenouard) -

- - Tests Passing - - [![Project Status](http://opensource.box.com/badges/active.svg)](http://opensource.box.com/badges) [![Test Status](https://github.com/anuraghazra/github-readme-stats/workflows/Test/badge.svg)](https://github.com/anuraghazra/github-readme-stats/) [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/major/MySQLTuner-perl.svg)](http://isitmaintained.com/project/major/MySQLTuner-perl "Average time to resolve an issue") From 5fac4cd07db68b29a1adc3d77b7d0b11995ffc77 Mon Sep 17 00:00:00 2001 From: Jean-Marie Renouard Date: Thu, 22 Jun 2023 23:00:28 +0200 Subject: [PATCH 6/7] Adding detection of non primary key tables Adding detection of non InnoDB tables Adding detection of non utf8 colums --- .gitignore | 3 +- mysqltuner.pl | 127 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 95 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index ec0d39e..551ca09 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ golang/prog-* test_db/** result* result_* -sql/*.sql \ No newline at end of file +sql/*.sql +sql/*.csv \ No newline at end of file diff --git a/mysqltuner.pl b/mysqltuner.pl index b8a6f09..34016c0 100644 --- a/mysqltuner.pl +++ b/mysqltuner.pl @@ -1120,6 +1120,7 @@ sub select_csv_file { print $l if $opt{debug}; } close $fh; + infoprint "CSV file $tfile created"; } sub human_size { @@ -5722,6 +5723,97 @@ sub get_wsrep_option { return $memValue; } +# REcommendations for Tables +sub mysql_table_structures { + subheaderprint "Table structures analysis"; + + my @primaryKeysNbTables = select_array( + "Select CONCAT(c.table_schema, ',' , c.table_name) +from information_schema.columns c +join information_schema.tables t using (TABLE_SCHEMA, TABLE_NAME) +where c.table_schema not in ('sys', 'mysql', 'information_schema', 'performance_schema') + and t.table_type = 'BASE TABLE' +group by c.table_schema,c.table_name +having sum(if(c.column_key in ('PRI', 'UNI'), 1, 0)) = 0" + ); + + my $tmpContent='Schema,Table'; + if ( scalar(@primaryKeysNbTables) > 0 ) { + badprint "Following table(s) don't have primary key:"; + foreach my $badtable (@primaryKeysNbTables) { + badprint "\t$badtable"; + push @{ $result{'Tables without PK'} }, $badtable; + $tmpContent.="\n$badtable"; + } + push @generalrec, + "Ensure that all table(s) get an explicit primary keys for performance, maintenance and also for replication"; + + } + else { + goodprint "All tables get a primary key"; + } + dump_into_file( "tables_without_primary_keys.csv", $tmpContent ); + + my @nonInnoDBTables = select_array( +"select CONCAT(table_schema, ',', table_name, ',', ENGINE) +FROM information_schema.tables t +WHERE ENGINE <> 'InnoDB' +and t.table_type = 'BASE TABLE' +and table_schema not in +('sys', 'mysql', 'performance_schema', 'information_schema')" + ); + $tmpContent='Schema,Table,Engine'; + if ( scalar(@nonInnoDBTables) > 0 ) { + badprint "Following table(s) are not InnoDB table:"; + push @generalrec, + "Ensure that all table(s) are InnoDB tables for performance and also for replication"; + foreach my $badtable (@nonInnoDBTables) { + badprint "\t$badtable"; + $tmpContent.="\n$badtable"; + } + } + else { + goodprint "All tables are InnoDB tables"; + } + dump_into_file( "tables_non_innodb.csv", $tmpContent ); + + my @nonutf8columns = select_array( +"SELECT CONCAT(table_schema, ',', table_name, ',', column_name, ',', CHARacter_set_name, ',', COLLATION_name, ',', data_type, ',', CHARACTER_MAXIMUM_LENGTH) +from information_schema.columns +WHERE table_schema not in ('sys', 'mysql', 'performance_schema', 'information_schema') +and (CHARacter_set_name NOT LIKE 'utf8%' +or COLLATION_name NOT LIKE 'utf8%');" + ); + $tmpContent='Schema,Table,Column, Charset, Collation, Data Type, Max Length'; + if ( scalar(@nonutf8columns) > 0 ) { + badprint "Following character columns(s) are not utf8 compliant:"; + push @generalrec, + "Ensure that all text colums(s) are UTF-8 compliant for encoding support and performance"; + foreach my $badtable (@nonutf8columns) { + badprint "\t$badtable"; + $tmpContent.="\n$badtable"; + } + } + else { + goodprint "All columns are UTF-8 compliant"; + } + dump_into_file( "columns_non_utf8.csv", $tmpContent ); + +my @utf8columns = select_array( +"SELECT CONCAT(table_schema, ',', table_name, ',', column_name, ',', CHARacter_set_name, ',', COLLATION_name, ',', data_type, ',', CHARACTER_MAXIMUM_LENGTH) +from information_schema.columns +WHERE table_schema not in ('sys', 'mysql', 'performance_schema', 'information_schema') +and (CHARacter_set_name LIKE 'utf8%' +or COLLATION_name LIKE 'utf8%');" + ); + $tmpContent='Schema,Table,Column, Charset, Collation, Data Type, Max Length'; + foreach my $badtable (@utf8columns) { + badprint "\t$badtable"; + $tmpContent.="\n$badtable"; + } + dump_into_file( "columns_utf8.csv", $tmpContent ); + +} # Recommendations for Galera sub mariadb_galera { subheaderprint "Galera Metrics"; @@ -5760,16 +5852,6 @@ sub mariadb_galera { infoprint "GCache is using " . hr_bytes_rnd( get_wsrep_option('gcache.mem_size') ); - #my @primaryKeysNbTables=(); - my @primaryKeysNbTables = select_array( - "Select CONCAT(c.table_schema,CONCAT('.', c.table_name)) -from information_schema.columns c -join information_schema.tables t using (TABLE_SCHEMA, TABLE_NAME) -where c.table_schema not in ('mysql', 'information_schema', 'performance_schema') - and t.table_type != 'VIEW' -group by c.table_schema,c.table_name -having sum(if(c.column_key in ('PRI', 'UNI'), 1, 0)) = 0" - ); infoprint "CPU cores detected : " . (cpu_cores); infoprint "wsrep_slave_threads: " . get_wsrep_option('wsrep_slave_threads'); @@ -5836,30 +5918,6 @@ having sum(if(c.column_key in ('PRI', 'UNI'), 1, 0)) = 0" "Flow control fraction seems to be OK (wsrep_flow_control_paused <= 0.02)"; } - if ( scalar(@primaryKeysNbTables) > 0 ) { - badprint "Following table(s) don't have primary key:"; - foreach my $badtable (@primaryKeysNbTables) { - badprint "\t$badtable"; - push @{ $result{'Tables without PK'} }, $badtable; - } - } - else { - goodprint "All tables get a primary key"; - } - my @nonInnoDBTables = select_array( -"select CONCAT(table_schema,CONCAT('.', table_name)) from information_schema.tables where ENGINE <> 'InnoDB' and table_schema not in ('mysql', 'performance_schema', 'information_schema')" - ); - if ( scalar(@nonInnoDBTables) > 0 ) { - badprint "Following table(s) are not InnoDB table:"; - push @generalrec, - "Ensure that all table(s) are InnoDB tables for Galera replication"; - foreach my $badtable (@nonInnoDBTables) { - badprint "\t$badtable"; - } - } - else { - goodprint "All tables are InnoDB tables"; - } if ( $myvar{'binlog_format'} ne 'ROW' ) { badprint "Binlog format should be in ROW mode."; push @adjvars, "binlog_format = ROW"; @@ -7126,6 +7184,7 @@ log_file_recommendations; # check log file content check_metadata_perf; # Show parameter impacting performance during analysis mysql_databases; # Show information about databases mysql_tables; # Show information about table column +mysql_table_structures; # Show information about table structures mysql_indexes; # Show information about indexes mysql_views; # Show information about views From 2910dc11a2820c3bc160012d1f2ecee208a2e3a4 Mon Sep 17 00:00:00 2001 From: Jean-Marie Renouard Date: Thu, 22 Jun 2023 23:01:20 +0200 Subject: [PATCH 7/7] Creating MT 2.2.0 --- mysqltuner.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mysqltuner.pl b/mysqltuner.pl index 34016c0..b71db85 100644 --- a/mysqltuner.pl +++ b/mysqltuner.pl @@ -1,5 +1,5 @@ #!/usr/bin/env perl -# mysqltuner.pl - Version 2.1.11 +# mysqltuner.pl - Version 2.2.0 # High Performance MySQL Tuning Script # Copyright (C) 2006-2023 Major Hayden - major@mhtx.net # Copyright (C) 2015-2023 Jean-Marie Renouard - jmrenouard@gmail.com @@ -57,7 +57,7 @@ use Cwd 'abs_path'; #use Env; # Set up a few variables for use in the script -my $tunerversion = "2.1.11"; +my $tunerversion = "2.2.0"; my ( @adjvars, @generalrec ); # Set defaults @@ -7225,7 +7225,7 @@ __END__ =head1 NAME - MySQLTuner 2.1.11 - MySQL High Performance Tuning Script + MySQLTuner 2.2.0 - MySQL High Performance Tuning Script =head1 IMPORTANT USAGE GUIDELINES