in reply to Perl and MySQL privileges

I'm unfamiliar with the syntax you're using. As far as I know, $HOST is for the host of the machine on which the MySQL server runs. Also, as far as I know, the server determines your hostname automatically during connection, checking it against the grant table.

Privileges to connect to a MySQL server exist independently of the user/group of the script -- they're determined by the hostname from which to connect to the server and the username and password provided when connecting.

With all that said, I usually use a connect string something like:

use DBI; my $host = "dbserver"; my $dsn = "DBI:mysql" . $host; my $user = "chromatic"; my $pass = ''; my $dbh = DBI->connect($dsn, $user, $pass);
If this is inappropriate for your purposes, let me know. I am slightly confused by your question, and offer my apologies if I have misunderstood.

Replies are listed 'Best First'.
Re: Followup on Perl and MySQL privileges
by fpi (Monk) on Mar 21, 2001 at 13:37 UTC
    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...