Sign up ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I can't seem to get Perl & MySQL to talk to each other on OS X 10.7 Lion.

I did all the installs by the book, I used Oracle's PKG installer for the latest MySQL Community Server, and I installed DBI and DBD::mysql via CPAN. There were not problems at all during the install, but, when I try to USE DBD::mysql to connect to my local DB server I get the following error:

install_driver(mysql) failed: 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: /usr/local/mysql/lib/libmysqlclient.16.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/ line 204.
 at (eval 3) line 3
Compilation failed in require at (eval 3) line 3.
Perhaps a required shared library or dll isn't installed where expected

After a lot of googling all I could find were suggested hacks, so I gave this one a go:

I had to update some of the paths in the instructions since on Lion it's Perl 5.12 not 5.10.

After doing that I got a new error:

dyld: lazy symbol binding failed: Symbol not found: _mysql_init
  Referenced from: /Library/Perl/5.12/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle
  Expected in: flat namespace

dyld: Symbol not found: _mysql_init
  Referenced from: /Library/Perl/5.12/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle
  Expected in: flat namespace

Trace/BPT trap: 5

There must be a simple way to get MySQL & Perl working on OS X? - HELP!

share|improve this question

migrated from Dec 15 '11 at 16:57

This question came from our site for system and network administrators.

3 Answers 3

up vote 3 down vote accepted

After quite a bit of frustration, I eventually found a simple solution that works.

The salient details are that you need to update the DYLD_LIBRARY_PATH to include /usr/local/mysql/lib. The easiest way of doing that is to add the following to your ~/.bashrc file:

export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"

I went into a little more detail in a blog post here:

share|improve this answer
This works great when using the terminal. But what if my script is being run from Apache? Then this export doesn't affect apache. Any way to make this a global/permanent change? – Rob Jul 5 at 20:36
I don't know if this is the correct solution, but after lots of searching, I found that copying the library to /usr/lib/ fixes the issue. I ran sudo cp /usr/local/mysql-5.6.25-osx10.8-x86_64/lib/libmysqlclient.18.dylib /usr/lib/ and that was it. – Rob Jul 5 at 21:08

I had the same symptoms, but a different problem: perl, by default, runs as 64bit executable, but my mysql installation and hence all its libraries are 32bit only. Forcing perl to run in 32bit mode solved it:

defaults write Prefer-32-Bit -bool yes
share|improve this answer

I was able to get this working using:

sudo ln -s /usr/local/mysql/lib/*.dylib .

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.