Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Followup on Perl and MySQL privileges

by fpi (Monk)
on Mar 21, 2001 at 13:37 UTC ( [id://65987]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl and MySQL privileges
in thread Perl and MySQL privileges

Followup:
I was enlightened with the following:

  • Thanks to chromatic and yakko, I learned that you can 'connect' to MySQL using DBI without specifying a database. Nowhere in the DBI man pages or O'Reilly's MySQL book does it say that, so I assumed you had to specify one. However, I modified chromatic's line above to go along with the syntax of the DBI man page:
     my $dsn = "DBI:mysql:host=$host";
    and it works fine.
  • chromatic's explanation cleared up the heart of my confusion: $HOST is the host of MySQL you want to connect to, NOT the host of the user (which is automatically determined). So yes, it is safe for me to hard-code 'localhost' into a script that will be installed on several machines, each one with their own MySQL database. Previously I had thought that I had to use the hostname() function to determine what machine the script was on and send that name to MySQL for login.
  • LD2 mentioned that MySQL should default to 'localhost', so I just tested this - if you change the same line to
     my $dsn = "DBI:mysql:";
    (leave the trailing colon), it defaults to localhost, and it works just fine.
Thanks for your help.

Oh, and about my syntax, I am just following the recommendation straight out of the DBI man page. I used the install_driver method because, like I said, I didn't know how else to connect to MySQL without connecting to a database...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://65987]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 09:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found