Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Getting DBD-mysql to work with Mac OS X Lion

by bmckenzie (Sexton)
on Jan 13, 2012 at 14:13 UTC ( #947746=perlquestion: print w/ replies, xml ) Need Help??
bmckenzie has asked for the wisdom of the Perl Monks concerning the following question:

Greetings,

I've recently returned to the Mac (OS X Version 10.7.2, to be precise) after years of developing simple web apps and maintaining our website using Perl on Windows. Everything was going fine recreating my development environment until this:

Can't load '/Library/Perl/5.12/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle' for module DBD::mysql: dlopen(/Library/Perl/5.12/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle, 1): Library not loaded: libmysqlclient.18.dylib Referenced from: /Library/Perl/5.12/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle Reason: image not found at /System/Library/Perl/5.12/darwin-thread-multi-2level/DynaLoader.pm line 204. at /Users/Bruce/Sites/public_html/cgi-bin/ptest.pl line 17 Compilation failed in require at /Users/Bruce/Sites/public_html/cgi-bin/ptest.pl line 17. BEGIN failed--compilation aborted at /Users/Bruce/Sites/public_html/cgi-bin/ptest.pl line 17.

A day of Googling has established that I'm not the first to see an error message like this with Mac OS X, but none of the suggested workarounds worked for me, either because they involve paths and files and things that don't seem (to me) to apply to my computer, or because I don't know what they're talking about.

The MySQL mysql-5.5.19-osx10.6-x86_64 installation appears to be OK; I see what I expect to see with phpMyAdmin.

I did have trouble installing DBD::mysql, but one of the aforementioned workarounds asserted that it was normal to have to force install. Which I did (four times, just to be sure :-). Attempts to reinstall with cpan are dismissed with a message saying everything is up to date.

I'm sure the solution will be obvious to many monks on Macs -- but please keep in mind that nothing about Unix (except its dissimilarity to Windows) is obvious to me.

Thanks so much

Bruce

Comment on Getting DBD-mysql to work with Mac OS X Lion
Download Code
Re: Getting DBD-mysql to work with Mac OS X Lion
by jethro (Monsignor) on Jan 13, 2012 at 14:32 UTC

    Not a solution, but you might do some detective work: The error message says "Library not loaded: libmysqlclient.18.dylib". So you could execute the following on the command line and see whether a) the file does not exit, b) the file exists but not where the script expects it or c) a different version of that file exists, for example libmysqlclient.19.dylib

    find / -name 'libmysqlclient*' -print

    Probably you can do the same with sherlock or whatever its called in the gui

    A look at line 17 (and preceding lines) of ptest.pl might also give some hints

Re: Getting DBD-mysql to work with Mac OS X Lion
by Eliya (Vicar) on Jan 13, 2012 at 14:57 UTC
    I did have trouble installing DBD::mysql, ...

    What exactly went wrong?   You do have the Xcode package installed, do you? (provides compiler, make, header files, etc.)

Re: Getting DBD-mysql to work with Mac OS X Lion
by luis.roca (Deacon) on Jan 13, 2012 at 15:08 UTC
    For now, just assume everything but the last error on or before line 17 is noise (If you could show that code to us it would be helpful). I would try to address that error first. It's very likely the rest will go away. If not, then you have some installation issues that can be addressed doing the following:
    1. Don't use the Perl included with Mac OSX. The system uses it along with modules and libraries your Mac came with.
    2. Install XCode (Can be done through the Mac App Store) to make sure things like gcc (C compiler) are on the machine and up to date.
    3. Keep a separate install of Perl, modules and libraries using either Activstate or Macports (I use and recommend Macports).
      • Once you install your own Perl using Macports you will start your Perl files with it's location. Likely: #!/opt/local/bin/perl
    4. Get yourself a good book/tutorial on Unix (BSD if you can).

    I would strongly suggest doing the above regardless the outcome of this particular problem you're having. Good luck!


    "...the adversities born of well-placed thoughts should be considered mercies rather than misfortunes." Don Quixote

      Yes, I installed XCode. However, it never occurred to me that a good solution would be the one I'm more accustomed to -- getting some packaged distribution of Perl and managing it myself (without affecting the actual OS). Sounds great.

      If possible, I'd like to get this working before taking the Unix crash course, so I have to ask: if there are two copies of Perl on the same machine, how do I keep the OS (and me) from getting confused when "perl" is typed on the command line -- will I have to use a different shebang line in scripts?

      A monk's post (in 2005) suggests that there will not be a problem with paths, but that I should uninstall DBI and reinstall it with the new Perl. Still true?

      Thanks again,

      Bruce

        You don't need to re-install perl, the built-in one works just fine, but the MySQL install from oracle just does not work with DBI and MySQL DBD client. Use the MacPorts mysql5 and mysql5 +server ports and everything falls into place. See my travails here <a href="http://groups.google.com/group/perl.dbi.users/browse_thread/thread/616d94b675c14b10?hl=en#"

        “ if there are two copies of Perl on the same machine, how do I keep the OS (and me) from getting confused when "perl" is typed on the command line -- will I have to use a different shebang line in scripts? ”

        If you're using Macports it will likely be: #!/opt/local/bin/perl and if you install modules through the ports library (e.g., $ sudo port install p5-Data-Dumper). However Macports does not have every module available so you will likely still have to navigate to that directory and install modules from there using MCPAN, cpanminus etc.

        To confirm the directory you can just use Mac OSX's Spotlight:

        1. (hit the Command and Spacebar keys at the same time). Type in 'Perl'
        2. Select 'Show all' at the top of the results. A window will appear.
        3. Under the window's search field select the 'plus' icon.
        4. Two drop down menus will appear in the row below. Change the second one to 'Folder'
        5. You will likely now see at least several folders (directories) with the name 'Perl'. Select the folders to see at the bottom of the window their exact location.

        Another tip: If you need to navigate to a specific location within a directory on the command line you can drag and drop that folder to the Mac OSX Terminal (The name of Apple's command line program). That will show the path. Place cd (change directory to:) in front of that path name and it takes you there. A nice trick for moving to something deeply nested.

        "...the adversities born of well-placed thoughts should be considered mercies rather than misfortunes." Don Quixote

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2014-11-24 22:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (147 votes), past polls