Skip to content

Commit a8ede22

Browse files
authored
Merge pull request #868 from major/copilot/add-default-prompt-username-password
Prompt for password when --user provided without --pass
2 parents b873cb8 + 180a5d6 commit a8ede22

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

mysqltuner.pl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,32 @@ sub mysql_setup {
11531153
return 1;
11541154
}
11551155
else {
1156+
# If password was not provided and noask is not set, prompt for it
1157+
if ( $opt{pass} eq 0 && $opt{'noask'} == 0 ) {
1158+
print STDERR
1159+
"Please enter your MySQL administrative password: ";
1160+
system("stty -echo >$devnull 2>&1");
1161+
my $password = <STDIN>;
1162+
system("stty echo >$devnull 2>&1");
1163+
chomp($password);
1164+
1165+
$mysqllogin = "-u $opt{user}";
1166+
if ( length($password) > 0 ) {
1167+
if ($is_win) {
1168+
$mysqllogin .= " -p\"$password\"";
1169+
}
1170+
else {
1171+
$mysqllogin .= " -p'$password'";
1172+
}
1173+
}
1174+
$mysqllogin .= $remotestring;
1175+
1176+
$loginstatus = `$mysqladmincmd ping $mysqllogin 2>&1`;
1177+
if ( $loginstatus =~ /mysqld is alive/ ) {
1178+
goodprint "Logged in using credentials with prompted password";
1179+
return 1;
1180+
}
1181+
}
11561182
badprint
11571183
"Attempted to use login credentials, but they were invalid";
11581184
exit 1;

0 commit comments

Comments
 (0)