Skip Menu |

This queue is for tickets about the DBD-mysql CPAN distribution.

Report information
The Basics
Id: 70640
Status: resolved
Priority: 0/
Queue: DBD-mysql

People
Owner: Nobody in particular
Requestors: perlbug [...] cg.cjb.net
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 4.017
Fixed in: (no value)



Subject: DBD::mysql does not support IPv6 addresses
$ perl -MDBI -e 'DBI->connect("DBI:mysql:database=foobar;host=[::1]", "", "")' DBI connect('database=foobar;host=[::1]','',...) failed: Unknown MySQL server host '[' (2) at -e line 1 $ This is because the colon is interpreted as a separator in the DSN string. Perl: v5.12.3 DBD::mysql: 4.017 DBI: 1.613 OS: Fedora 14
RT-Send-CC: CAPTTOFU [...] cpan.org
On Wed Aug 31 11:41:43 2011, roblang wrote: Show quoted text
> $ perl -MDBI -e 'DBI->connect("DBI:mysql:database=foobar;host=[::1]", > "", "")' > DBI connect('database=foobar;host=[::1]','',...) failed: Unknown MySQL > server host '[' (2) at -e line 1 > $ > > This is because the colon is interpreted as a separator in the DSN string.
While this is true, if I do not use the square brackets: $ perl -MDBI -e 'DBI->connect("DBI:mysql:database=foobar;host=::1","", "")' I can connect without problems. This is consistent with how DBD::Pg treats connection strings; with the quare brackets it does not work, without them it just works. If there would be some compelling reason to insist on having the possibility to use square brackets, please let me know. -- Mike
From: tim [...] cpanel.net
On Mon Sep 16 05:27:35 2013, MICHIELB wrote: Show quoted text
> On Wed Aug 31 11:41:43 2011, roblang wrote:
> > $ perl -MDBI -e 'DBI->connect("DBI:mysql:database=foobar;host=[::1]", > > "", "")' > > DBI connect('database=foobar;host=[::1]','',...) failed: Unknown > > MySQL > > server host '[' (2) at -e line 1 > > $ > > > > This is because the colon is interpreted as a separator in the DSN > > string.
> > While this is true, if I do not use the square brackets: > > $ perl -MDBI -e 'DBI->connect("DBI:mysql:database=foobar;host=::1","", > "")' > > I can connect without problems. > > This is consistent with how DBD::Pg treats connection strings; with > the quare brackets it does not work, without them it just works. > > If there would be some compelling reason to insist on having the > possibility to use square brackets, please let me know. > -- > Mike
I've found that: perl -MDBI -e 'DBI->connect("DBI:mysql:database=foobar;host=::1","", "")' works only as an edge case. I.e., the _OdbcParse function interprets ::1 as an empty host value. This works as well: perl -MDBI -e 'DBI->connect("DBI:mysql:database=foobar;host=;","", "")' If I supply a whole IPv6 address: perl -MDBI -e 'DBI->connect("DBI:mysql:database=foobar;host= 2620:0:28a0:2107:2718::3","", "")' Then I get an error: failed: Can't connect to MySQL server on '2620' (107) at -e line 1 The regular expression is only allowing the first segment of the IPv6 address to appear due to the use of colons as separators.
From: tim [...] cpanel.net
On Tue Feb 11 18:34:31 2014, timmullin wrote: Show quoted text
> On Mon Sep 16 05:27:35 2013, MICHIELB wrote:
> > On Wed Aug 31 11:41:43 2011, roblang wrote:
> > > $ perl -MDBI -e 'DBI-
> > > >connect("DBI:mysql:database=foobar;host=[::1]",
> > > "", "")' > > > DBI connect('database=foobar;host=[::1]','',...) failed: Unknown > > > MySQL > > > server host '[' (2) at -e line 1 > > > $ > > > > > > This is because the colon is interpreted as a separator in the DSN > > > string.
> > > > While this is true, if I do not use the square brackets: > > > > $ perl -MDBI -e 'DBI-
> > >connect("DBI:mysql:database=foobar;host=::1","",
> > "")' > > > > I can connect without problems. > > > > This is consistent with how DBD::Pg treats connection strings; with > > the quare brackets it does not work, without them it just works. > > > > If there would be some compelling reason to insist on having the > > possibility to use square brackets, please let me know. > > -- > > Mike
> > I've found that: > perl -MDBI -e 'DBI->connect("DBI:mysql:database=foobar;host=::1","", > "")' > works only as an edge case. I.e., the _OdbcParse function interprets > ::1 as an empty host value. This works as well: > perl -MDBI -e 'DBI->connect("DBI:mysql:database=foobar;host=;","", > "")' > > If I supply a whole IPv6 address: > perl -MDBI -e 'DBI->connect("DBI:mysql:database=foobar;host= > 2620:0:28a0:2107:2718::3","", "")' > > Then I get an error: > failed: Can't connect to MySQL server on '2620' (107) at -e line 1 > > The regular expression is only allowing the first segment of the IPv6 > address to appear due to the use of colons as separators.
The fix for this is pretty easy, just two lines. If I change the regular expression in _OdbcParse to ignore any separators that are contained within brackets, I can freely use IPv6 addresses in the connection string if I put brackets around them: diff --git a/lib/DBD/mysql.pm b/lib/DBD/mysql.pm index 1a2111a..e66e16c 100644 --- a/lib/DBD/mysql.pm +++ b/lib/DBD/mysql.pm @@ -58,9 +58,10 @@ sub _OdbcParse($$$) { return; } while (length($dsn)) { - if ($dsn =~ /([^:;]*)[:;](.*)/) { + if ($dsn =~ /([^:;]*\[.*]|[^:;]*)[:;](.*)/) { $val = $1; $dsn = $2; + $val =~ s/\[|]//g; # Remove [] if present, the rest of the code prefers plain IPv6 addresses } else { $val = $dsn; $dsn = '';
RT-Send-CC: tim [...] cpanel.net
On Thu Feb 13 16:40:31 2014, timmullin wrote: Show quoted text
> The fix for this is pretty easy, just two lines. If I change the > regular expression in _OdbcParse to ignore any separators that are > contained within brackets, I can freely use IPv6 addresses in the > connection string if I put brackets around them: > > diff --git a/lib/DBD/mysql.pm b/lib/DBD/mysql.pm > index 1a2111a..e66e16c 100644 > --- a/lib/DBD/mysql.pm > +++ b/lib/DBD/mysql.pm > @@ -58,9 +58,10 @@ sub _OdbcParse($$$) { > return; > } > while (length($dsn)) { > - if ($dsn =~ /([^:;]*)[:;](.*)/) { > + if ($dsn =~ /([^:;]*\[.*]|[^:;]*)[:;](.*)/) { > $val = $1; > $dsn = $2; > + $val =~ s/\[|]//g; # Remove [] if present, the rest > of the code prefers plain IPv6 addresses > } else { > $val = $dsn; > $dsn = '';
The first half of your fix was already supplied by someone else and applied to the code base. I now added the second part: https://github.com/perl5-dbi/DBD-mysql/commit/01817870eceac55d0bad1f180d339375b4373088 Thanks for your contribution!