DBD::mysql fails to install on Mac OS X
Some versions of DBD::mysql fail to install on Mac OS X with this error:
DBI Connection failed: install_driver(mysql) failed: Can't load '.../lib/perl5/darwin-2level/auto/DBD/mysql/mysql.bundle' for module DBD::mysql: dlopen(.../lib/perl5/darwin-2level/auto/DBD/mysql/mysql.bundle, 1): Library not loaded: libmysqlclient.18.dylib
# Referenced from: .../lib/perl5/darwin-2level/auto/DBD/mysql/mysql.bundle
# Reason: image not found at .../lib/5.16.3/darwin-2level/DynaLoader.pm line 194.
The issue is that for some reason the DBD::mysql mysql.bundle
references a relative path to libmysqlclient.18.dylib
.
To check you can do:
otool -L .../lib/perl5/darwin-2level/auto/DBD/mysql/mysql.bundle
Check that libmysqlclient.18.dylib
file that the bundle references is a relative path or does not exist.
To work around the issue, I use this:
chmod 755 mysql.bundle
install_name_tool -change libmysqlclient.18.dylib \
/usr/local/mysql/lib/libmysqlclient.18.dylib \
mysql.bundle
chmod 555 mysql.bundle
Replace /usr/local/mysql/lib/libmysqlclient.18.dylib
with the full path of libmysqlclient.18.dylib
on your system.