Merge pull request #65 from rene-s/master
added option mysqlcmd so you can give a custom mysql command to mysqltun...
This commit is contained in:
commit
fa47d9cffa
1 changed files with 31 additions and 16 deletions
|
@ -78,6 +78,7 @@ GetOptions(\%opt,
|
||||||
'skipsize',
|
'skipsize',
|
||||||
'checkversion',
|
'checkversion',
|
||||||
'mysqladmin=s',
|
'mysqladmin=s',
|
||||||
|
'mysqlcmd=s',
|
||||||
'help',
|
'help',
|
||||||
'buffers',
|
'buffers',
|
||||||
);
|
);
|
||||||
|
@ -104,6 +105,7 @@ sub usage {
|
||||||
" --user <username> Username to use for authentication\n".
|
" --user <username> Username to use for authentication\n".
|
||||||
" --pass <password> Password to use for authentication\n".
|
" --pass <password> Password to use for authentication\n".
|
||||||
" --mysqladmin <path> Path to a custom mysqladmin executable\n".
|
" --mysqladmin <path> Path to a custom mysqladmin executable\n".
|
||||||
|
" --mysqlcmd <path> Path to a custom mysql executable\n".
|
||||||
"\n".
|
"\n".
|
||||||
" Performance and Reporting Options\n".
|
" Performance and Reporting Options\n".
|
||||||
" --skipsize Don't enumerate tables and their types/sizes (default: on)\n".
|
" --skipsize Don't enumerate tables and their types/sizes (default: on)\n".
|
||||||
|
@ -250,7 +252,7 @@ sub os_setup {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Checks to see if a MySQL login is possible
|
# Checks to see if a MySQL login is possible
|
||||||
my ($mysqllogin,$doremote,$remotestring);
|
my ($mysqllogin,$doremote,$remotestring,$mysqlcmd);
|
||||||
sub mysql_setup {
|
sub mysql_setup {
|
||||||
$doremote = 0;
|
$doremote = 0;
|
||||||
$remotestring = '';
|
$remotestring = '';
|
||||||
|
@ -269,6 +271,19 @@ sub mysql_setup {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($opt{mysqlcmd}) {
|
||||||
|
$mysqlcmd = $opt{mysqlcmd};
|
||||||
|
} else {
|
||||||
|
$mysqlcmd = `which mysql`;
|
||||||
|
}
|
||||||
|
chomp($mysqlcmd);
|
||||||
|
if (! -e $mysqlcmd && $opt{mysqlcmd}) {
|
||||||
|
badprint "Unable to find the mysql command you specified: ".$mysqlcmd."\n";
|
||||||
|
exit;
|
||||||
|
} elsif (! -e $mysqlcmd) {
|
||||||
|
badprint "Couldn't find mysql in your \$PATH. Is MySQL installed?\n";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
# Are we being asked to connect via a socket?
|
# Are we being asked to connect via a socket?
|
||||||
if ($opt{socket} ne 0) {
|
if ($opt{socket} ne 0) {
|
||||||
|
@ -406,13 +421,13 @@ sub mysql_setup {
|
||||||
my (%mystat,%myvar,$dummyselect);
|
my (%mystat,%myvar,$dummyselect);
|
||||||
sub get_all_vars {
|
sub get_all_vars {
|
||||||
# We need to initiate at least one query so that our data is useable
|
# We need to initiate at least one query so that our data is useable
|
||||||
$dummyselect = `mysql $mysqllogin -Bse "SELECT VERSION();"`;
|
$dummyselect = `$mysqlcmd $mysqllogin -Bse "SELECT VERSION();"`;
|
||||||
my @mysqlvarlist = `mysql $mysqllogin -Bse "SHOW /*!50000 GLOBAL */ VARIABLES;"`;
|
my @mysqlvarlist = `$mysqlcmd $mysqllogin -Bse "SHOW /*!50000 GLOBAL */ VARIABLES;"`;
|
||||||
foreach my $line (@mysqlvarlist) {
|
foreach my $line (@mysqlvarlist) {
|
||||||
$line =~ /([a-zA-Z_]*)\s*(.*)/;
|
$line =~ /([a-zA-Z_]*)\s*(.*)/;
|
||||||
$myvar{$1} = $2;
|
$myvar{$1} = $2;
|
||||||
}
|
}
|
||||||
my @mysqlstatlist = `mysql $mysqllogin -Bse "SHOW /*!50000 GLOBAL */ STATUS;"`;
|
my @mysqlstatlist = `$mysqlcmd $mysqllogin -Bse "SHOW /*!50000 GLOBAL */ STATUS;"`;
|
||||||
foreach my $line (@mysqlstatlist) {
|
foreach my $line (@mysqlstatlist) {
|
||||||
$line =~ /([a-zA-Z_]*)\s*(.*)/;
|
$line =~ /([a-zA-Z_]*)\s*(.*)/;
|
||||||
$mystat{$1} = $2;
|
$mystat{$1} = $2;
|
||||||
|
@ -424,7 +439,7 @@ sub get_all_vars {
|
||||||
# have_* for engines is deprecated and will be removed in MySQL 5.6;
|
# have_* for engines is deprecated and will be removed in MySQL 5.6;
|
||||||
# check SHOW ENGINES and set corresponding old style variables.
|
# check SHOW ENGINES and set corresponding old style variables.
|
||||||
# Also works around MySQL bug #59393 wrt. skip-innodb
|
# Also works around MySQL bug #59393 wrt. skip-innodb
|
||||||
my @mysqlenginelist = `mysql $mysqllogin -Bse "SHOW ENGINES;" 2>$devnull`;
|
my @mysqlenginelist = `$mysqlcmd $mysqllogin -Bse "SHOW ENGINES;" 2>$devnull`;
|
||||||
foreach my $line (@mysqlenginelist) {
|
foreach my $line (@mysqlenginelist) {
|
||||||
if ($line =~ /^([a-zA-Z_]+)\s+(\S+)/) {
|
if ($line =~ /^([a-zA-Z_]+)\s+(\S+)/) {
|
||||||
my $engine = lc($1);
|
my $engine = lc($1);
|
||||||
|
@ -441,7 +456,7 @@ sub get_all_vars {
|
||||||
|
|
||||||
sub security_recommendations {
|
sub security_recommendations {
|
||||||
print "\n-------- Security Recommendations -------------------------------------------\n";
|
print "\n-------- Security Recommendations -------------------------------------------\n";
|
||||||
my @mysqlstatlist = `mysql $mysqllogin -Bse "SELECT CONCAT(user, '\@', host) FROM mysql.user WHERE password = '' OR password IS NULL;"`;
|
my @mysqlstatlist = `$mysqlcmd $mysqllogin -Bse "SELECT CONCAT(user, '\@', host) FROM mysql.user WHERE password = '' OR password IS NULL;"`;
|
||||||
if (@mysqlstatlist) {
|
if (@mysqlstatlist) {
|
||||||
foreach my $line (sort @mysqlstatlist) {
|
foreach my $line (sort @mysqlstatlist) {
|
||||||
chomp($line);
|
chomp($line);
|
||||||
|
@ -453,7 +468,7 @@ sub security_recommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_replication_status {
|
sub get_replication_status {
|
||||||
my $slave_status = `mysql $mysqllogin -Bse "show slave status\\G"`;
|
my $slave_status = `$mysqlcmd $mysqllogin -Bse "show slave status\\G"`;
|
||||||
my ($io_running) = ($slave_status =~ /slave_io_running\S*\s+(\S+)/i);
|
my ($io_running) = ($slave_status =~ /slave_io_running\S*\s+(\S+)/i);
|
||||||
my ($sql_running) = ($slave_status =~ /slave_sql_running\S*\s+(\S+)/i);
|
my ($sql_running) = ($slave_status =~ /slave_sql_running\S*\s+(\S+)/i);
|
||||||
if ($io_running eq 'Yes' && $sql_running eq 'Yes') {
|
if ($io_running eq 'Yes' && $sql_running eq 'Yes') {
|
||||||
|
@ -533,7 +548,7 @@ sub check_storage_engines {
|
||||||
infoprint "Status: ";
|
infoprint "Status: ";
|
||||||
my $engines;
|
my $engines;
|
||||||
if (mysql_version_ge(5, 1)) {
|
if (mysql_version_ge(5, 1)) {
|
||||||
my @engineresults = `mysql $mysqllogin -Bse "SELECT ENGINE,SUPPORT FROM information_schema.ENGINES WHERE ENGINE NOT IN ('performance_schema','MyISAM','MERGE','MEMORY') ORDER BY ENGINE ASC"`;
|
my @engineresults = `$mysqlcmd $mysqllogin -Bse "SELECT ENGINE,SUPPORT FROM information_schema.ENGINES WHERE ENGINE NOT IN ('performance_schema','MyISAM','MERGE','MEMORY') ORDER BY ENGINE ASC"`;
|
||||||
foreach my $line (@engineresults) {
|
foreach my $line (@engineresults) {
|
||||||
my ($engine,$engineenabled);
|
my ($engine,$engineenabled);
|
||||||
($engine,$engineenabled) = $line =~ /([a-zA-Z_]*)\s+([a-zA-Z]+)/;
|
($engine,$engineenabled) = $line =~ /([a-zA-Z_]*)\s+([a-zA-Z]+)/;
|
||||||
|
@ -550,7 +565,7 @@ sub check_storage_engines {
|
||||||
print "$engines\n";
|
print "$engines\n";
|
||||||
if (mysql_version_ge(5)) {
|
if (mysql_version_ge(5)) {
|
||||||
# MySQL 5 servers can have table sizes calculated quickly from information schema
|
# MySQL 5 servers can have table sizes calculated quickly from information schema
|
||||||
my @templist = `mysql $mysqllogin -Bse "SELECT ENGINE,SUM(DATA_LENGTH),COUNT(ENGINE) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema','mysql') AND ENGINE IS NOT NULL GROUP BY ENGINE ORDER BY ENGINE ASC;"`;
|
my @templist = `$mysqlcmd $mysqllogin -Bse "SELECT ENGINE,SUM(DATA_LENGTH),COUNT(ENGINE) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema','mysql') AND ENGINE IS NOT NULL GROUP BY ENGINE ORDER BY ENGINE ASC;"`;
|
||||||
foreach my $line (@templist) {
|
foreach my $line (@templist) {
|
||||||
my ($engine,$size,$count);
|
my ($engine,$size,$count);
|
||||||
($engine,$size,$count) = $line =~ /([a-zA-Z_]*)\s+(\d+)\s+(\d+)/;
|
($engine,$size,$count) = $line =~ /([a-zA-Z_]*)\s+(\d+)\s+(\d+)/;
|
||||||
|
@ -558,13 +573,13 @@ sub check_storage_engines {
|
||||||
$enginestats{$engine} = $size;
|
$enginestats{$engine} = $size;
|
||||||
$enginecount{$engine} = $count;
|
$enginecount{$engine} = $count;
|
||||||
}
|
}
|
||||||
$fragtables = `mysql $mysqllogin -Bse "SELECT COUNT(TABLE_NAME) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema','mysql') AND Data_free > 0 AND NOT ENGINE='MEMORY';"`;
|
$fragtables = `$mysqlcmd $mysqllogin -Bse "SELECT COUNT(TABLE_NAME) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema','mysql') AND Data_free > 0 AND NOT ENGINE='MEMORY';"`;
|
||||||
chomp($fragtables);
|
chomp($fragtables);
|
||||||
} else {
|
} else {
|
||||||
# MySQL < 5 servers take a lot of work to get table sizes
|
# MySQL < 5 servers take a lot of work to get table sizes
|
||||||
my @tblist;
|
my @tblist;
|
||||||
# Now we build a database list, and loop through it to get storage engine stats for tables
|
# Now we build a database list, and loop through it to get storage engine stats for tables
|
||||||
my @dblist = `mysql $mysqllogin -Bse "SHOW DATABASES"`;
|
my @dblist = `$mysqlcmd $mysqllogin -Bse "SHOW DATABASES"`;
|
||||||
foreach my $db (@dblist) {
|
foreach my $db (@dblist) {
|
||||||
chomp($db);
|
chomp($db);
|
||||||
if ($db eq "information_schema") { next; }
|
if ($db eq "information_schema") { next; }
|
||||||
|
@ -573,7 +588,7 @@ sub check_storage_engines {
|
||||||
# MySQL 3.23/4.0 keeps Data_Length in the 5th (0-based) column
|
# MySQL 3.23/4.0 keeps Data_Length in the 5th (0-based) column
|
||||||
@ixs = (1, 5, 8);
|
@ixs = (1, 5, 8);
|
||||||
}
|
}
|
||||||
push(@tblist, map { [ (split)[@ixs] ] } `mysql $mysqllogin -Bse "SHOW TABLE STATUS FROM \\\`$db\\\`"`);
|
push(@tblist, map { [ (split)[@ixs] ] } `$mysqlcmd $mysqllogin -Bse "SHOW TABLE STATUS FROM \\\`$db\\\`"`);
|
||||||
}
|
}
|
||||||
# Parse through the table list to generate storage engine counts/statistics
|
# Parse through the table list to generate storage engine counts/statistics
|
||||||
$fragtables = 0;
|
$fragtables = 0;
|
||||||
|
@ -619,10 +634,10 @@ sub check_storage_engines {
|
||||||
# Auto increments
|
# Auto increments
|
||||||
my %tblist;
|
my %tblist;
|
||||||
# Find the maximum integer
|
# Find the maximum integer
|
||||||
my $maxint = `mysql $mysqllogin -Bse "SELECT ~0"`;
|
my $maxint = `$mysqlcmd $mysqllogin -Bse "SELECT ~0"`;
|
||||||
|
|
||||||
# Now we build a database list, and loop through it to get storage engine stats for tables
|
# Now we build a database list, and loop through it to get storage engine stats for tables
|
||||||
my @dblist = `mysql $mysqllogin -Bse "SHOW DATABASES"`;
|
my @dblist = `$mysqlcmd $mysqllogin -Bse "SHOW DATABASES"`;
|
||||||
foreach my $db (@dblist) {
|
foreach my $db (@dblist) {
|
||||||
chomp($db);
|
chomp($db);
|
||||||
|
|
||||||
|
@ -637,7 +652,7 @@ sub check_storage_engines {
|
||||||
# MySQL 3.23/4.0 keeps Data_Length in the 5th (0-based) column
|
# MySQL 3.23/4.0 keeps Data_Length in the 5th (0-based) column
|
||||||
@ia = (0, 9);
|
@ia = (0, 9);
|
||||||
}
|
}
|
||||||
push(@{$tblist{$db}}, map { [ (split)[@ia] ] } `mysql $mysqllogin -Bse "SHOW TABLE STATUS FROM \\\`$db\\\`"`);
|
push(@{$tblist{$db}}, map { [ (split)[@ia] ] } `$mysqlcmd $mysqllogin -Bse "SHOW TABLE STATUS FROM \\\`$db\\\`"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
my @dbnames = keys %tblist;
|
my @dbnames = keys %tblist;
|
||||||
|
@ -708,7 +723,7 @@ sub calculations {
|
||||||
$size += (split)[0] for `find $myvar{'datadir'} -name "*.MYI" 2>&1 | xargs du -L $duflags 2>&1`;
|
$size += (split)[0] for `find $myvar{'datadir'} -name "*.MYI" 2>&1 | xargs du -L $duflags 2>&1`;
|
||||||
$mycalc{'total_myisam_indexes'} = $size;
|
$mycalc{'total_myisam_indexes'} = $size;
|
||||||
} elsif (mysql_version_ge(5)) {
|
} elsif (mysql_version_ge(5)) {
|
||||||
$mycalc{'total_myisam_indexes'} = `mysql $mysqllogin -Bse "SELECT IFNULL(SUM(INDEX_LENGTH),0) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema') AND ENGINE = 'MyISAM';"`;
|
$mycalc{'total_myisam_indexes'} = `$mysqlcmd $mysqllogin -Bse "SELECT IFNULL(SUM(INDEX_LENGTH),0) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema') AND ENGINE = 'MyISAM';"`;
|
||||||
}
|
}
|
||||||
if (defined $mycalc{'total_myisam_indexes'} and $mycalc{'total_myisam_indexes'} == 0) {
|
if (defined $mycalc{'total_myisam_indexes'} and $mycalc{'total_myisam_indexes'} == 0) {
|
||||||
$mycalc{'total_myisam_indexes'} = "fail";
|
$mycalc{'total_myisam_indexes'} = "fail";
|
||||||
|
|
Loading…
Reference in a new issue