Skip to content

Commit

Permalink
Read MySQL username from my.cnf, too.
Browse files Browse the repository at this point in the history
Resolves #353.
  • Loading branch information
theory committed Sep 9, 2017
1 parent cdbb40d commit 1962a6e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -14,6 +14,8 @@ Revision history for Perl extension App::Sqitch
runtime was using 32-bit integers. Fix by casting the version to text
in the query, before Perl ever see it. Thanks to Malte Legenhausen for
the report (#343).
- The MySQL engine will now read the username from MySQL configuration
files. Thanks to Eliot Alter for the bug report (#353).

0.9996 2017-07-17T18:33:12Z
- Fixed an error where Oracle sometimes truncated timestamp formats so
Expand Down
32 changes: 21 additions & 11 deletions lib/App/Sqitch/Engine/mysql.pm
Expand Up @@ -10,7 +10,7 @@ use Locale::TextDomain qw(App-Sqitch);
use App::Sqitch::Plan::Change;
use Path::Class;
use Moo;
use App::Sqitch::Types qw(DBH URIDB ArrayRef Bool Str);
use App::Sqitch::Types qw(DBH URIDB ArrayRef Bool Str HashRef);
use namespace::autoclean;
use List::MoreUtils qw(firstidx);

Expand Down Expand Up @@ -39,24 +39,34 @@ sub registry_destination {
return $uri->as_string;
}

has _mycnf => (
is => 'rw',
isa => HashRef,
default => sub {
eval 'require MySQL::Config; 1' or return {};
return scalar MySQL::Config::parse_defaults('my', [qw(client mysql)]);
},
);

sub username {
my $self = shift;
return $self->SUPER::username || $self->_mycnf->{user};
}

sub password {
my $self = shift;
return $self->SUPER::password || $self->_mycnf->{password};
}

has dbh => (
is => 'rw',
isa => DBH,
lazy => 1,
default => sub {
my $self = shift;
$self->use_driver;

my $uri = $self->registry_uri;
my $pass = $self->password || do {
# Read the default MySQL configuration.
# http://dev.mysql.com/doc/refman/5.0/en/option-file-options.html
if (eval 'require MySQL::Config; 1') {
my %cfg = MySQL::Config::parse_defaults('my', [qw(client mysql)]);
$cfg{password};
}
};
my $dbh = DBI->connect($uri->dbi_dsn, scalar $self->username, $pass, {
my $dbh = DBI->connect($uri->dbi_dsn, scalar $self->username, $self->password, {
PrintError => 0,
RaiseError => 0,
AutoCommit => 1,
Expand Down
10 changes: 5 additions & 5 deletions lib/sqitch-passwords.pod
Expand Up @@ -99,12 +99,12 @@ contains lines specify authentication rules as follows:

=item MySQL

For MySQL, if the L<MySQL::Config> module is installed, passwords can be
specified in the L<F</etc/my.cnf> and
F<~/.my.cnf> files|http://dev.mysql.com/doc/refman/5.1/en/password-security-user.html#idm139947650158560>.
For MySQL, if the L<MySQL::Config> module is installed, usernames and
passwords can be specified in the
L<F</etc/my.cnf> and F<~/.my.cnf> files|https://dev.mysql.com/doc/refman/5.7/en/password-security-user.html>.
These files must limit access only to the current user (C<0600>). Sqitch will
look for a password under the C<[client]> and C<[mysql]> sections, in that
order.
look for a username and password under the C<[client]> and C<[mysql]>
sections, in that order.

=item Oracle

Expand Down
2 changes: 2 additions & 0 deletions lib/sqitch.pod
Expand Up @@ -335,6 +335,8 @@ script templates.

=item C<--quiet>

sqitch --quiet

Suppress normal output messages. Error messages will still be emitted to
C<STDERR>. Overrides any value specified by C<--verbose>.

Expand Down

3 comments on commit 1962a6e

@ealter
Copy link
Contributor

@ealter ealter commented on 1962a6e Jan 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do you think you'll be able to cut a release that includes this commit?

@theory
Copy link
Collaborator Author

@theory theory commented on 1962a6e Mar 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soon? Need to find more folks to help with maintenance.

@theory
Copy link
Collaborator Author

@theory theory commented on 1962a6e Mar 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ealter, v0.9997 went out late last week. Enjoy!

Please sign in to comment.