sdyates has asked for the wisdom of the Perl Monks concerning the following question:

My code ran fine on Redhat linux. I was able to connect tot he same version of MYSQL: 3.23.

The code is now running on FreeBSD 4.8. The code is fine, but I cannot connect to the DB. I have installed the DBD and the dbi driver, before I pull my hair out, I seek the wisdom of the monks to point me in the right direction.

Error Message

install_driver(mysql) failed: Can't locate DBD/mysql.pm in @INC (@INC +contains: /usr/local/lib/perl5/5.8.7/i386-freebsd /usr/local/lib/perl +5/5.8.7 /usr/local/lib/perl5/site_perl/5.8.7/i386-freebsd /usr/local/ +lib/perl5/site_perl/5.8.7 /usr/local/lib/perl5/site_perl/5.6.2 /usr/l +ocal/lib/perl5/site_perl/5.005 /usr/local/lib/perl5/site_perl .) at ( +eval 10) line 3. Perhaps the DBD::mysql perl module hasn't been fully installed, or perhaps the capitalisation of 'mysql' isn't right. Available drivers: ADO, ExampleP, Multiplex, Proxy. at /usr/local/apache/cgi-bin/ISee/ISeeSupportDisplaySWAT.pl line 164

code generating message

my $dbh = DBI->connect("dbi:mysql:$DBName:$IP", "$db_user", "$db_passw +ord", {RaiseError => 0, PrintError => 0} ) or err_trap("Cannot connect to the database");

I tried adding an extra : in the code between dbi::mysql and was surprised to get the followinf error messahe

Can't connect(dbi::mysql:support: username password HASH(0x842cb58)), +no database driver specified and DBI_DSN env var not set at /usr/loca +l/apache/cgi-bin/ISee/ISeeSupportDisplaySWAT.pl line 163

Any thoughts?

Am I using the wrong drivers? ----- 11jan06: Update. First, thanks again for your comments. It's nice to have a second voice over my shoulder.

On Linux, I used ppm, but could not find it on Unix, however, I did find MCPAN and used it to properly set up DBD abd DBI. Here is what I used:

perl -MCPAN -e 'install DBI' perl -MCPAN -e 'install DBD::mysql'

So thanks for the help, and I hope my update will assist others.

Signed, one of the faithful greatful ;)

Replies are listed 'Best First'.
Re: Can't Connect to MySQL after port
by suaveant (Parson) on Jan 10, 2006 at 04:30 UTC
    It is telling you all you need to know in that first error
    install_driver(mysql) failed: Can't locate DBD/mysql.pm in ...
    You need to find where the module is on your system and put a use lib to the appropriate directory. I don't know if FreeBSD has the locate command but in Linux I would use it to find DBD/mysql.pm and add a use lib to the directory that DBD is in... mine is in /usr/lib/perl5/DBD/mysql.pm so I would do a use lib '/usr/lib/perl5';...

    if that doesn't work I would say you have a broken install, and how did you install it? (are the mysql client C libraries installed?)

                    - Ant
                    - Some of my best work - (1 2 3)

Re: Can't Connect to MySQL after port
by jZed (Prior) on Jan 10, 2006 at 05:46 UTC
    > install_driver(mysql) failed: Can't locate DBD/mysql.pm in @INC

    That means that either DBD::mysql is not properly installed (in which case, re-install it), or else the location it is installed in is not in your @INC (in which case use "use lib" to add the directory where it is located to the @INC).

    > I tried adding an extra : in the code between dbi::mysql

    Since DBI treats whatever is between the first two colons as the driver, you are essentially telling DBI to operate using the driver named ''. Hence the message "no database driver specified".