简体   繁体   中英

How can I check if a Perl module (DBD::mysql) is properly installed?

I am using XAMPP on Mac OS X Yosemite, and I am trying to communicate with my MySQL database using Perl.

This requires two things: (1) DBI and (2) the mysql driver module, DBD::mysql.

I ran into a lot of trouble installing the DBD::mysql portion. However, after following some instructions online, it now looks like DBD::mysql is installed, but I am skeptical that it has correctly.

In Terminal , when I load up cpan and then type "install DBD::mysql", it responds, "DBD::mysql is up to date (4.032)".

From the looks of it, then, it is installed. However, I am worried that what I've installed is enough for it to say, "Hey, I am installed!", but not enough for it to actually be functional, which would be why I'm having errors show up when I try to connect to my database with Perl:

install_driver(mysql) failed: Can't load '/Library/Perl/5.18/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle' for module DBD::mysql: dlopen(/Library/Perl/5.18/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle, 1): Library not loaded: libmysqlclient.18.dylib

Referenced from: /Library/Perl/5.18/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle
  Reason: image not found at /System/Library/Perl/5.18/darwin-thread-multi-2level/DynaLoader.pm line 194.
 at (eval 6) line 3.
Compilation failed in require at (eval 6) line 3.
Perhaps a required shared library or dll isn't installed where expected
 at login.pl line 9.

Relevant Perl code snippet:

my $dbh = DBI->connect(          
    "dbi:mysql:dbname=TEST", 
    "root",                          
    "",                          
    { RaiseError => 1 },         
) or die $DBI::errstr;

I am trying to troubleshoot whether this is a problem with my installation of DBD::mysql, or if it is my Perl code.

How can I verify whether my installation of DBD::mysql is all good? Better yet, how can I stop getting this error?

Thank you.

You could wrap the connect() call into an eval block to catch this error, however you don't have many options left if it crashes, probably just to try and produce a more user-friendly error messsage and then die anyway.

As for why you are getting the error, try checking where libmysqlclient.18.dylib lives on your system. It seems like it was somewhere where it could be found during compilation of the DBD::mysql driver but not during your script's runtime. Assuming it hasn't been accidentially uninstalled, adding its directory to the DYLD_LIBRARY_PATH variable should work. I don't know what config to add the path to to make that addition permanent on OSX though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM