In preparation to seeking help from the Perl Monks, scholarship on this problem includes, but is not limited to, the following: a careful study of my self-study textbook (MySQL and Perl for the Web by Paul DuBois), and numerous hyperlinks in Google....all without success. I'm learning Perl and in following the textbook that I'm using, I'm trying to employ an easier way to connect to my mySQL server (the SQL database is on my web hosted site) using DBI's "connect_with_option_file" method and .my.cnf option file. In other words, in lieu of using the following instruction (which works perfectly well) in each of my cgi source programs:
$dbh = DBI->connect("DBI:mysql:gmacfadd_webdb:localhost","gmacfadd +_webdev2","webdevpass2", {PrintError => 0, RaiseError => 1});
I've put the following connection code information in a library function module called WebDB.pm and placed it in the directory home/gmacfadd/public_html/cgi-bin/dubois on my hosted site:
#! /usr/bin/perl -wT package WebDB; use strict; use DBI; my $host_name = "localhost"; my $db_name = "gmacfadd_webdb"; my $dsn = "DBI:mysql:database=$db_name;host=$host_name"; # Connect to MySQL server using hardwired name and password sub connect { return (DBI->connect ($dsn, "gmacfadd_webdev2", "webdevpass2", {PrintError => 0, RaiseError =>1})); } sub connect_with_option_file { $dsn .= ";mysql_read_default_file=$ENV{HOME}/.my.cnf"; return (DBI->connect ($dsn, undef, undef, {PrintError => 0, RaiseError =>1})); } 1; #return true
In accordance with the above code, the hardwired connection methods using name and password also work fine. It is the with connect_with_otion_file that I'm having difficulty. I have duly created the .my.cnf file in my root directory (C:/.my.cnf) on my Windows XP system, specifiying the following client program connection parameters:
[client] user="gmacfadd_webdev2" password="webdevpass2"
I have created and confirmed that the aforementioned user and password are existing in mySQL. When I then try to run the CGI containing the following:
#! /usr/bin/perl -wT # intro7b.cgi - use WebDB to connect use strict; # FORCE ALL VARIABLES TO BE DECLARED BEFORE + USE use DBI; # IMPORT THE DATABASE INTERFACE METHODS use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use lib qw(/home/gmacfadd/public_html/cgi-bin/dubois); use WebDB; my ($dbh, $sth, $count, $user); # DECLARE VARIABLES $dbh = WebDB::connect_with_option_file();
I receive the following error message: DBI connect('database=gmacfadd_webdb;host=localhost; mysql_read_default_file=/.my.cnf','',...) failed: Access denied for user: 'gmacfadd@localhost' (Using password: NO) at /home/gmacfadd/public_html/cgi-bin/dubois/WebDB.pm line 20 Can you please help me correct my problem?

In reply to connect_with_option_file by gmacfadden

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.