Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

DBD mysql can't detect mysql installation

by nitin1704 (Sexton)
on Jul 06, 2012 at 08:31 UTC ( #980226=perlquestion: print w/ replies, xml ) Need Help??
nitin1704 has asked for the wisdom of the Perl Monks concerning the following question:

I installed DWIMPerl on my Windows 64bit machine, and it seems that it came pre-installed with DBI and DBD::mysql. Then I went on to install MySQL Server 5.5. Then using a Perl script, I tried to list all the drivers and data sources. But it doesn't show the mysql databases:

#!/usr/bin/perl use warnings; use strict; use DBI; print "Available DBI Drivers and Data Sources:\n\n"; my @drivers = DBI->available_drivers('quiet'); my @sources; foreach my $driver (@drivers) { print "$driver\n"; @sources = eval { DBI->data_sources($driver) }; if($@) { print "\tError: ",substr($@,0,60),"\n"; } elsif (@sources) { foreach(@sources) { print "\t$_\n"; } } else { print "\tNo known data sources\n"; } }

The script generated this output:

Available DBI Drivers and Data Sources: ADO No known data sources DBM DBI:DBM:f_dir=. ExampleP dbi:ExampleP:dir=. File DBI:File:f_dir=. Gofer No known data sources ODBC dbi:ODBC:dBASE Files dbi:ODBC:Excel Files dbi:ODBC:MS Access Database Pg No known data sources Proxy Error: install_driver(Proxy) failed: Can't locate RPC/PlClient +.pm i SQLite No known data sources Sponge No known data sources mysql No known data sources Press any key to continue . . .

And the  mysql> show databases; on the same machine shows this:

mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec)

Comment on DBD mysql can't detect mysql installation
Select or Download Code
Re: DBD mysql can't detect mysql installation
by moritz (Cardinal) on Jul 06, 2012 at 09:42 UTC

    That's OK. You can connect to your mysql database with DBI->connect(...) even though your databases aren't shown as "known data sources".

    The background is that the mysql driver doesn't know which database to connect to (there could be multiple running on your machine, or none at all, and access happens over the network), and which username and password to use.

    You can also see that only file-based DBD modules list known data sources, because all the others have the same problems as the mysql driver.

      Thanks Moritz. I tried querying the database and it works. BTW, is Access really a file based DB?

      You can also see that only file-based DBD modules list known data sources, because all the others have the same problems as the mysql driver.

      That is not strictly true. Although the ODBC ones listed are file based in this example the real reason they are listed is because DBD::ODBC's datasources method can query the ODBC Driver Manager for the data sources. If the OP had had a data source for MS SQL Server or Oracle they would have been listed as well.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://980226]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-10-31 11:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (216 votes), past polls