3

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!

migrated from serverfault.com Dec 15 '11 at 16:57

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

4

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

  • 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 '15 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 '15 at 21:08
3

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
0

I was able to get this working using:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .