I ran into this issue a few years back and was never able to resolve it. Since then I've just always specified the host in the dsn string. Below is an example script where the first case without specifying host=$host fails, but the second case with host=$host succeeds. Any pointers appreciated. It wasn't obvious to me where in DBD/mysql.pm it was reading the config file. I did step through the debugger forever, until it failed to connect, but never saw where it was reading the config file.
#!/bin/env perl use warnings; use strict; use DBI; my $db = "****"; my $host = "****"; my $cfg_file = "/tmp/my.cnf"; my ($dsn, $dbh); print STDERR "Without host=\$host\n"; $dsn = "dbi:mysql:mysql_ssl=1;database=$db;mysql_read_default_file=$cf +g_file;mysql_read_default_group=test_group"; $dbh = DBI->connect($dsn); print STDERR "\nWith host=\$host\n"; $dsn = "dbi:mysql:mysql_ssl=1;database=$db;mysql_read_default_file=$cf +g_file;mysql_read_default_group=test_group;host=$host"; $dbh = DBI->connect($dsn); print "\$dbh = $dbh\n";
outputs:
Without host=$host DBI connect('mysql_ssl=1;database=****;mysql_read_default_file=/tmp/my +.cnf;mysql_read_default_group=test_group','',...) failed: Can't conne +ct to local MySQL server through socket '/var/run/mysql.sock' (2) at +/tmp/test_db.pl line 12. With host=$host $dbh = DBI::db=HASH(0xa00318a18)
The /tmp/my.cnf looks like:
[test_group] host=**** port=3306 database=**** user=**** password=**** no-auto-rehash ssl=1

Update: This is on a cygwin system with the latest cygwin based perl and associated modules. I just tried it on a linux system and it works without specifying host=$host


In reply to Re: Reading host from defaults file with DBD::mysql by Danny
in thread Reading host from defaults file with DBD::mysql by Llew_Llaw_Gyffes

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.