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...