MySQL & Perl on OS X Mavericks

After upgrading to Mavericks, my local development environment stopped working — more specifically, Perl would no longer talk to MySQL.

Recently, I decided to figure it out.

I was getting the following error from a Perl script that was trying to talk to my database. The database was there, it was accessible from the command line, and I verified that my Perl DBI libraries were installed.

install_driver(mysql) failed: Can't load '/Library/Perl/5.16/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle' for module DBD::mysql: dlopen(/Library/Perl/5.16/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle, 1): Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Library/Perl/5.16/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle
  Reason: image not found at /System/Library/Perl/5.16/darwin-thread-multi-2level/ line 194.
 at (eval 21) line 3.

After some searching, I realized that Perl was trying to load MySQL, but from the wrong location. Perl expected the libmysqlclient.dylib to live at /usr/lib but Mavericks had installed it at /usr/local.

So, I created a symlink to redirect Perl to the right location.

sudo ln -s /usr/local/mysql-5.6.17-osx10.7-x86_64/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

It should be noted that libmysqlclient.dylib will contain version information in the filename and Perl will expect it there. Your version is likely different than mine, so be sure to update it as needed. If you’re wondering, what version Perl is looking for, read your error message and that will tell you.

Tom Rouillard

Leave a Reply

Your email address will not be published. Required fields are marked *