I'm finding the MySQL privilege system to be rather confusing when it comes to how my Perl program relates to it.
I have a Perl program accessing MySQL on the same (Unix) machine, and I've already determined that MySQL is running, and that a particular database does NOT exist, so now I am attempting to create it (assume variables are defined accordingly):
my $drh=DBI->install_driver('mysql');
my $rc = $drh->func('createdb',$DATABASE,$HOST,$USER,$PASSWORD,'admin'
+) or die "Can't create\n";
Now I understand that when MySQL checks authentication against the mysql:user table, the Hostname takes a priority match over User and Password (which drives me
nuts).
My question is this: does this mean that I can specify whatever
$HOST I want, regardless of whatever host I am really using, in order to match an entry in the mysql:user table?
And is connecting to MySQL like this independent of whether or not the Perl program is run as root or with root ownership? I am asking because if I get the program to work on the command line, then I get privilege errors when running the program as a CGI using Apache. I think the confusion may arise when using
use Sys::Hostname;
$HOST=hostname();
sometimes $HOST defaults to 'localhost', other times it defaults to the actual hostname of the machine. Should I just hard code 'localhost' as my host into the DBI commands?
I've read
man DBI, man DBD::mysql, the Perl chapters of O'Reilly's MySQL book, and the MySQL site. I was hoping your experience can explain it to me or give me some insight into the 'proper' way of setting up privileges in running a perl program to do some admin work (create a non-existing db, create and alter tables) in MySQL.
By the way, my Perl program was using MySQL just fine. It wasn't until I installed the program on another machine did I realize these privileges are more complicated that I had expected.... I'm confused.....