Installing DBD::mysql on Mac OS X 10.7 "Lion"

I’ve run into this problem every time I’ve set-up a new computer recently, so — in the interest of remembering where to look for the solution next time — here’s a quick “note to future self” post on installing MySQL and DBD::mysql on Mac OS X 10.7 “Lion.”

First, the binary installers for MySQL and PostgreSQL for OS X have gotten so good that I don’t bother compiling either from source anymore. In fact, the new PostgreSQL installer comes with a nifty “Application Stack Builder” tool that does 1-click post-installation installation of helpful PostgreSQL add-ons like PostGIS (previously, one of my least favourite things to install). The same goes for the MySQL binary installer: installing MySQL, a preference pane for starting/stopping the server, and a startup item to ensure that it’s always running after a reboot is all included.

Okay, so that’s great, but what about when I actually want to connect to MySQL from something like Perl? Well, to get started, I need to install the MySQL driver, DBD::mysql. Unfortunately, cpanm bails with this log message:

There are a few helpful posts out there on the Internets, but none of the suggestions resolved the issue for me.

In there end, there were two steps that were necessary to get things working:

  • 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).

  • 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).

There you go. That worked for me. Maybe it’ll work for you too. Enjoy.


export DYLD_LIBRARY_PATH=/usr/local/mysql/lib


What version of mysql are you using with Mac OSX 10.7?


I add 2 lines in my ~/.bash_profile
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"

next I look cflags in mysql_config -cflags
then testuser and testpassword I set up in mysqladmin and ...
reopen terminal and...

sudo perl Makefile.PL --libs="-L/usr/local/mysql/lib -lmysqlclient" --cflags="-I/usr/local/mysql/include/mysql -g -Os -arch i386 -fno-common -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL" --mysql_config=/usr/local/mysql/bin/mysql_config --testuser=YOUR_TESTUSER --testpassword=YOUR_PASSWORD_FOR_TESTUSER

hope its help =)
any questions? (

Leave a comment

About Phillip Smith

user-pic Phillip Smith is a digital publishing consultant, online advocacy specialist, and strategic convener. And I blog about Perl.