Merge pull request #685 from jmrenouard/master
Adding checks for Primary keys, non innodb tables and non UTF-8 columns
This commit is contained in:
commit
46f0aead18
3 changed files with 114 additions and 47 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -15,4 +15,5 @@ golang/prog-*
|
|||
test_db/**
|
||||
result*
|
||||
result_*
|
||||
sql/*.sql
|
||||
sql/*.sql
|
||||
sql/*.csv
|
|
@ -2,9 +2,8 @@
|
|||
|
||||
[](https://www.buymeacoffee.com/jmrenouard)
|
||||
|
||||
[](https://travis-ci.org/major/MySQLTuner-perl)
|
||||
[](http://opensource.box.com/badges)
|
||||
[](http://opensource.box.com/badges)
|
||||
[](https://github.com/anuraghazra/github-readme-stats/)
|
||||
[](http://isitmaintained.com/project/major/MySQLTuner-perl "Average time to resolve an issue")
|
||||
[](http://isitmaintained.com/project/major/MySQLTuner-perl "Percentage of issues still open")
|
||||
[](https://opensource.org/licenses/GPL-3.0/)
|
||||
|
@ -28,8 +27,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/)
|
||||
|
||||

|
||||
|
||||
## Stargazers over time
|
||||
|
||||
[](https://starcharts.herokuapp.com/major/MySQLTuner-perl)
|
||||
|
|
152
mysqltuner.pl
152
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
|
||||
|
@ -1120,6 +1120,7 @@ sub select_csv_file {
|
|||
print $l if $opt{debug};
|
||||
}
|
||||
close $fh;
|
||||
infoprint "CSV file $tfile created";
|
||||
}
|
||||
|
||||
sub human_size {
|
||||
|
@ -2750,6 +2751,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 +3802,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";
|
||||
|
@ -5717,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";
|
||||
|
@ -5755,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');
|
||||
|
@ -5831,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";
|
||||
|
@ -7121,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
|
||||
|
@ -7161,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
|
||||
|
||||
|
|
Loading…
Reference in a new issue