0

I have installed CPAN module DBD::mysql via sudo cpan install DBD::mysql in order to run the code below, however I keep getting the error message:

Can't locate loadable object for module DBD::mysql in @INC (@INC contains: 
  /sw/lib/perl5/5.12.3/darwin-thread-multi-2level
  /sw/lib/perl5/5.12.3
  /sw/lib/perl5/darwin-thread-multi-2level
  /sw/lib/perl5
  /sw/lib/perl5/darwin
  /Library/Perl/5.12/darwin-thread-multi-2level
  /Library/Perl/5.12
  /Network/Library/Perl/5.12/darwin-thread-multi-2level
  /Network/Library/Perl/5.12
  /Library/Perl/Updates/5.12.3/darwin-thread-multi-2level
  /Library/Perl/Updates/5.12.3
  /System/Library/Perl/5.12/darwin-thread-multi-2level
  /System/Library/Perl/5.12
  /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level
  /System/Library/Perl/Extras/5.12
  .
)
at dbi_write.pl line 11
Compilation failed in require at dbi_write.pl line 11.
BEGIN failed--compilation aborted at dbi_write.pl line 11.

This is my code

#!/usr/bin/perl

#use lib '/usr/bin/cpan';
use strict;
use FileHandle;
use File::Spec;
use DBI;
use DBD::mysql;
Borodin
  • 126,100
  • 9
  • 70
  • 144
  • Can you confirm with `perldoc -lm DBI DBD::mysql` that both modules got installed to where you think they are? – user2926055 Dec 05 '13 at 19:55
  • Yes, I've confirmed that the modules are installed successfully. I've also checked to see where the modules were installed. On my mac OSX, I have two different Perl locations, one in Systems/Library, and the other in sw/lib. I've copied and pasted the DBI and DBD directories into both. The same error message remains. – missPamelaHeart Dec 06 '13 at 21:37

2 Answers2

2

Did your CPAN install succeed? If it did, then the module has been installed in the wrong place for the version of Perl you are running.

Look at the CPAN log to see where DBD::mysql has been installed. The answer lies there, and the fix depends on where it has been installed and why it isn't in your Perl's @INC.

Do you have multiple installations of Perl?

By the way, you don't have to use DBD::mysql. DBI will load it automatically when you call DBI->new specifying a MySQL source. That tidies up the code at the expense of loading the driver module at run time - a small price to pay.

Borodin
  • 126,100
  • 9
  • 70
  • 144
  • I've confirmed that the modules are installed successfully. I've also checked to see where the modules were installed. On my mac OSX, I have two different Perl locations, one in Systems/Library, and the other in sw/lib. I've copied and pasted the DBI and DBD directories into both. The same error message remains. – missPamelaHeart Dec 06 '13 at 21:37
  • As I said, you need to look *where* the module has been installed. If you're not sure then paste the CPAN log here. What did you do to confirm that it had been installed correctly? There is clearly something wrong as your program can't find it. – Borodin Dec 07 '13 at 02:47
0

I solved it by doing the following:

copy libmysqlclient.18.dylib into /usr/lib/

Also, there are two different Perls in my Mac OS X. One in /usr/local/ActivePerl5.16/ And another in /Systems/Library/Per/Perl5.12