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

I'm using a Perl script to display the contents of a table. On running the script I get a 'Can't locate DBD/mysql.pm in @INC' error. mysql was installed on my mac via homebrew so I'm guessing that's why there is something amiss in my @INC search path?

#!/usr/bin/perl use strict; use warnings; use DBI; my $dbfile = "bank"; my $dsn = "dbi:mysql:dbname=$dbfile"; my $user = "donfox1"; my $password = "nodxof"; my $dbh = DBI->connect($dsn, $user, $password, { PrintError => 0, RaiseError => 1, AutoCommit => 1, FetchHashKeyName => 'NAME_lc', }); my $sql = 'SELECT name, address FROM branch'; my $sth = $dbh->prepare($sql); $sth->execute(1,10); while (my @row = $sth->fetchrow_array) { print "name: $row[0] address: $row[1]\n"; } $sth->execute(12, 17); while (my $row = $sth->fetchrow_hashref) { print "fname: $row->{name} lname: $row->{address}\n"; } $dbh->disconnect; print "\tSTUBB_1\n";

Output on running the script is: ./connect.pl install_driver(mysql) failed: Can't locate DBD/mysql.pm in @INC (you may need to install the DBD::mysql module) (@INC contains: /Library/Perl/5.18/darwin-thread-multi-2level /Library/Perl/5.18 /Network/Library/Perl/5.18/darwin-thread-multi-2level /Network/Library/Perl/5.18 /Library/Perl/Updates/5.18.2 /System/Library/Perl/5.18/darwin-thread-multi-2level /System/Library/Perl/5.18 /System/Library/Perl/Extras/5.18/darwin-thread-multi-2level /System/Library/Perl/Extras/5.18 .) at (eval 4) line 3. Perhaps the DBD::mysql perl module hasn't been fully installed, or perhaps the capitalisation of 'mysql' isn't right. Available drivers: DBM, ExampleP, File, Gofer, Proxy, SQLite, Sponge.

Replies are listed 'Best First'.
Re: Can't locate DBD/mysql.pm in @INC
by AppleFritter (Vicar) on Mar 21, 2015 at 22:54 UTC
    You say MySQL was installed, but was the DBI driver, DBD::mysql? That's not part of MySQL, and it appears it's missing.

      I just did an install of DBD::mysql from CPAN. Getting the same results as before. Does Installing Perl from homebrew place files in wrong locations for CPAN modules?

Re: Can't locate DBD/mysql.pm in @INC
by sauoq (Abbot) on Mar 22, 2015 at 03:51 UTC

    I'm guessing that homebrew doesn't actually replace the system perl, which is the one you are trying to run (#!/usr/bin/perl). Maybe try changing that to #!/usr/bin/env perl or calling your script as perl script.pl. If that doesn't work, you'll probably need to fix your path or put the full path to homebrew's perl on the shebang line.

    -sauoq
    "My two cents aren't worth a dime.";

      I've resolved the problem by uninstalling mysql and maria-DB then reinstalling maria-DB with homebrew. There had been a problem with symlinks previously. Now I can access my databases; Thanks!

Re: Can't locate DBD/mysql.pm in @INC
by sauoq (Abbot) on Mar 22, 2015 at 03:51 UTC
    Duplicated node. Please reap.
    -sauoq
    "My two cents aren't worth a dime.";