Assume that the code already verifies that mysqld is running.use DBI; use DBD::mysql; #although not used in this example
| Hostname | User | Password | (permissions...) |
| localhost | root | abcdefg | (full...) |
| localhost | (blank) | (blank) | (limited...) |
This method works fine for MySQL and on my machine, until I started installing the script on another machine with the same architecture.Then I began to get privilege errors and I couldn't figure out why. I knew from the docs that this statement only works for the localhost access, but it still should have worked. Finally I discovered the reason: because you can't specify a user and password with this method, it defaults to the user running the perl program. if you specified a MySQL root password in your grant table, then you can't run your perl program as root (or any user with a localhost entry with a password in your grant table for that matter). You need to run the program as any user without a password.my @installed_databases = DBI->data_sources('mysql');
This install_driver method comes straight out of the DBI docs. I used it because at first I didn't know it was possible to connect to MySQL without specifying a database. It works fine, but it had the same problem as above, in that you couldn't run the program as a user that had a password in the MySQL grant table, eg. as root.my $drh=DBI->install_driver('mysql'); my @installed_databases= $drh->func($HOST,'_ListDBs');
which worked fine,and you could even specify a --host tag if you needed. (By the way, those are `back quotes`, not 'single quotes', if you've never used them before). It didn't matter if you ran the program as root or any other user. However,the problem with this was that it would definitely not be portable to other database engines that I would try in the future.my @installed_databases = `mysqlshow --user=$USERNAME --password=$PASS +WORD`;
You can leave out the host=$HOST to default to localhost (but leave the trailing colon after mysql, i.e. 'DBI:mysql:').my $dbh=DBI->connect("DBI:mysql:host=$HOST",$USER,$PASSWORD); my @installed_databases= $dbh->func('_ListDBs');
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Checking installed MySQL databases with DBI
by Dragonfly (Priest) on Mar 22, 2001 at 13:58 UTC | |
|
Re: Checking installed MySQL databases with DBI
by tadman (Prior) on Mar 23, 2001 at 00:07 UTC | |
|
Re: Checking installed MySQL databases with DBI
by elwarren (Priest) on Mar 23, 2001 at 02:19 UTC | |
|
Re: Checking installed MySQL databases with DBI
by $code or die (Deacon) on Mar 23, 2001 at 17:54 UTC | |
|
Re: Checking installed MySQL databases with DBI
by geektron (Curate) on Jan 11, 2005 at 21:11 UTC |