Take the 2-minute tour ×
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/DynaLoader.pm 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: http://arkoftech.wordpress.com/2011/02/10/fixing-dbdmysql-for-mysql-5-5-89-under-macos-10-6-x/

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 serverfault.com Dec 15 '11 at 16:57

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

2 Answers 2

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: http://www.bartbusschots.ie/blog/?p=2186

share|improve this answer

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 com.apple.versioner.perl Prefer-32-Bit -bool yes
share|improve this answer

Your Answer


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