Installing DBD::mysql on Mac OS X Lion

I was trying to install the perl module DBD::mysql on Mac OS X Lion. I faced some hassles. Here are a couple of useful links (Thanks!). I had some peculiar problems of my own, so this post is a “note-to-self” for the next time :

According to Joe Di Pol’s blog, OS X works slightly backwards to what most of us from Linux and Solaris backgrounds understand – compiled binaries look at a dynamic library, which in turns says where it is, rather than the traditional way of thinking which is to include a library search path in the compiled binary.

cpan[1]> install DBD::mysql

So, when it comes down to testing (make test), it fails.

# Failed test 'use DBD::mysql;'
# at t/00base.t line 21.
# Tried to use 'DBD::mysql'.
# Error: Can't load '/Users/aalap/.cpan/build/DBD-mysql-4.020-9nL8LG/blib/arch/auto/DBD/mysql/mysql.bundle' for module DBD::mysql: dlopen(/Users/aalap/.cpan/build/DBD-mysql-4.020-9nL8LG/blib/arch/auto/DBD/mysql/mysql.bundle, 2): Library not loaded: libmysqlclient.18.dylib

There are two solutions:

  1. Symlinking ‘libmysqlclient.XX.dylib’ from ‘/usr/local/mysql/lib’ to ‘/usr/lib/’ (where XX is the version of the library that is available to link to).
  2. Run install_name_tool command, install DBD::mysql buillds

  3. sudo install_name_tool -id /usr/local/mysql-5.5.21-osx10.6-x86_64/lib

    otool -D `mdfind libmysqlclient.18.dylib`

Alas, it still failed for me. Building successfully doesn’t mean it is installed. CPAN performs make install only after make test. I had changed my root password. The Makefile expects “” (NULL) password. I had to pass a valid user and a valid password. Passing arguments to the Makefile to ensure that the tests run using a proper MySQL user (the Makefile defaults to the system user running the tests, if no other user is provided, which fails for me as that user doesn’t exist). After a few more turns I realized, it lacks permissions to place some files in /Library/Perl/5.12/darwin-thread-multi-2level/Bundle/DBD. I decided to use root and run sudo CPAN. The way to do it is:

cpan[2] o conf makepl_arg "--testuser=root --testpassword=Whatever_my_password_is"

Now run install DBD::mysql again

cpan[3] install DBD::mysql


Running make install
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Installing /Library/Perl/5.12/darwin-thread-multi-2level/auto/DBD/mysql/
Installing /Library/Perl/5.12/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle
Installing /Library/Perl/5.12/darwin-thread-multi-2level/Bundle/DBD/
Installing /Library/Perl/5.12/darwin-thread-multi-2level/DBD/
Installing /Library/Perl/5.12/darwin-thread-multi-2level/DBD/mysql/
Installing /Library/Perl/5.12/darwin-thread-multi-2level/DBD/mysql/INSTALL.pod
Installing /usr/local/share/man/man3/Bundle::DBD::mysql.3pm
Installing /usr/local/share/man/man3/DBD::mysql.3pm
Installing /usr/local/share/man/man3/DBD::mysql::INSTALL.3pm
Appending installation info to /Library/Perl/Updates/5.12.3/darwin-thread-multi-2level/perllocal.pod
/usr/bin/make install -- OK

All’s well that end’s well. Annoying errors had me stuck me for a while.

Leave a Reply