Skip to content

Commit 26e38ee

Browse files
authored
Fix dsn for ipv4 on older perl-dbd-mysql versions
* ipv4 address with brackts causes error on connection. add brackets only when ip contains ':'. * removing dependency on 4.031 perl-dbd-mysql
1 parent c460ac5 commit 26e38ee

File tree

8 files changed

+12
-9
lines changed

8 files changed

+12
-9
lines changed

debian/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Package: mha4mysql-manager
1111
Architecture: all
1212
Depends: ${misc:Depends}, ${perl:Depends},
1313
libdbi-perl,
14-
libdbd-mysql-perl (>= 4.031),
14+
libdbd-mysql-perl,
1515
libconfig-tiny-perl,
1616
liblog-dispatch-perl,
1717
libparallel-forkmanager-perl,

lib/MHA/DBHelper.pm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ sub connect_util {
152152
my $port = shift;
153153
my $user = shift;
154154
my $password = shift;
155-
my $dsn = "DBI:mysql:;host=[$host];port=$port;mysql_connect_timeout=1";
155+
my $dsn_host = $host =~ m{:} ? '[' . $host . ']' : $host;
156+
my $dsn = "DBI:mysql:;host=$dsn_host;port=$port;mysql_connect_timeout=1";
156157
my $dbh = DBI->connect( $dsn, $user, $password, { PrintError => 0 } );
157158
return $dbh;
158159
}
@@ -195,7 +196,8 @@ sub connect {
195196

196197
$self->{dbh} = undef;
197198
unless ( $self->{dsn} ) {
198-
$self->{dsn} = "DBI:mysql:;host=[$host];port=$port;mysql_connect_timeout=4";
199+
my $dsn_host = $host =~ m{:} ? '[' . $host . ']' : $host;
200+
$self->{dsn} = "DBI:mysql:;host=$dsn_host;port=$port;mysql_connect_timeout=4";
199201
}
200202
my $defaults = {
201203
PrintError => 0,

lib/MHA/HealthCheck.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ sub connect {
9494
$raise_error = 0;
9595
}
9696
my $log = $self->{logger};
97+
my $dsn_host = $self->{ip} =~ m{:} ? '[' . $self->{ip} . ']' : $self->{ip};
9798
$self->{dbh} = DBI->connect(
98-
"DBI:mysql:;host=[$self->{ip}];"
99+
"DBI:mysql:;host=$dsn_host;"
99100
. "port=$self->{port};mysql_connect_timeout=$connect_timeout",
100101
$self->{user},
101102
$self->{password},

rpm/masterha_manager.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Requires: perl(Config::Tiny)
1313
Requires: perl(Log::Dispatch)
1414
Requires: perl(Parallel::ForkManager)
1515
Requires: mha4mysql-node >= 0.54
16-
Requires: perl(DBD::mysql) >= 4.031
16+
Requires: perl(DBD::mysql)
1717
Source0: mha4mysql-manager-%{version}.tar.gz
1818

1919
%description

tests/t/bulk_tran_insert.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
my ( $port, $user, $pass, $start, $stop, $commit_interval ) = @ARGV;
88
my $pk = $start;
99
my $committed_rows = 0;
10-
my $dsn = "DBI:mysql:test;host=[127.0.0.1];port=$port";
10+
my $dsn = "DBI:mysql:test;host=127.0.0.1;port=$port";
1111
my $dbh = DBI->connect( $dsn, $user, $pass );
1212
if ( $commit_interval == 1 ) {
1313
$dbh->do("SET AUTOCOMMIT=1");

tests/t/insert.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
my ( $port, $user, $pass, $start, $stop, $single_tran, $rollback ) = @ARGV;
88
$rollback = 0 if ( !defined($rollback) );
99

10-
my $dsn = "DBI:mysql:test;host=[127.0.0.1];port=$port";
10+
my $dsn = "DBI:mysql:test;host=127.0.0.1;port=$port";
1111
my $dbh = DBI->connect( $dsn, $user, $pass );
1212

1313
my $sth;

tests/t/insert_binary.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
close($in);
2222
unlink $file;
2323

24-
my $dsn = "DBI:mysql:test;host=[127.0.0.1];port=$port";
24+
my $dsn = "DBI:mysql:test;host=127.0.0.1;port=$port";
2525
my $dbh = DBI->connect( $dsn, $user, $pass );
2626

2727
my $value= $buf;

tests/t/tran_insert.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
my ( $port, $user, $pass, $start, $stop, $commit_interval ) = @ARGV;
88
my $pk = $start;
99
my $committed_rows = 0;
10-
my $dsn = "DBI:mysql:test;host=[127.0.0.1];port=$port";
10+
my $dsn = "DBI:mysql:test;host=127.0.0.1;port=$port";
1111
my $dbh = DBI->connect( $dsn, $user, $pass );
1212
if ( $commit_interval == 1 ) {
1313
$dbh->do("SET AUTOCOMMIT=1");

0 commit comments

Comments
 (0)