0

I installed MySQL 5.6.10 onto Mac OSX 10.8.2, in /usr/local/mysql-5.6.10-osx10.7-x86_64/. I then tried to run a Perl program that connects to a MySQL database using DBI and DBD::mysql. I got the following errors:

install_driver(mysql) failed: Can't load '/Users/chap/perl5/perlbrew/perls/perl-
5.16.1/lib/site_perl/5.16.1/darwin-2level/auto/DBD/mysql/mysql.bundle' 
for module DBD::mysql: dlopen(/Users/chap/perl5/perlbrew/perls/perl-
5.16.1/lib/site_perl/5.16.1/darwin-2level/auto/DBD/mysql/mysql.bundle, 
1): Library not loaded: /usr/local/lib/libmysqlclient.18.dylib

Perhaps a required shared library or dll isn't installed where expected

(This worked fine when I had used 'brew' (not related to perlbrew) to install mysql 5.5 into its own directory, /usr/local/Cellar/. Since brew doesn't yet know about 5.6, I installed it manually.)

I'm able to start mysqld and connect successfully from mysql command line. Does this error indicate that there's a problem with Perl's DBD::mysql module? It's up-to-date; maybe it can't talk to MySqL 5.6?

Thanks!

Chap
  • 3,649
  • 2
  • 46
  • 84

2 Answers2

1

I have had several problems installing DBD::mysql on Mac, and I found the following to work on Mac OSX 10.6.8 with Perl 5.16.1 and MySQL 5.5.27 where mysql is installed in /usr/local/. Please double check any paths and usernames used in the commands below.

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


curl -kL http://search.cpan.org/CPAN/authors/id/C/CA/CAPTTOFU/DBD-mysql-4.021.tar.gz > DBD-mysql-4.021.tar.gz
gunzip -c DBD-mysql-4.021.tar.gz | tar xopf - 

cd DBD-mysql-4.021 && perl ./Makefile.pl --testuser root --libs="-L/usr/local/mysql/lib -lmysqlclient -lpthread"

install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib blib/arch/auto/DBD/mysql/mysql.bundle

make test
sudo make install

And then check with a connection (assuming you still have the test database and the anonymous user enabled)

perl -e "use DBD::mysql; my $dbh = DBI->connect('dbi:mysql:test:localhost::3306:mysql_socket=/tmp/mysql.sock'); $dbh->disconnect();"
Astuanax
  • 667
  • 5
  • 18
  • 1
    This gave me enough clues to find an answer, which was simply to create a symlink **/usr/local/bin/libmysqlclient.18.dylib** -> **/usr/local/mysql/lib/libmysqlclient.18.dylib**. At least, things are now working. – Chap Mar 10 '13 at 18:01
  • Just my 5 cents: had a very similar problem, already for the second time (well, that I am conscious of, maybe in the past I actually had it more often, but wasn't aware that this was the root of it), but for me it was that the libmysqlclient was where it was supposed to be, i.e. in `/usr/local/mysql/lib/libmysqlclient.18.dylib`, but the symlink in `/usr/lib` somehow managed to point to itself (MacOS X - don't ask:-S). I renamed that self-referential POS and made a symlink `/usr/local/mysql/lib/libmysqlclient.18.dylib -> /usr/lib/libmysqlclient.18.dylib`. Thx for bringing me on the right track! – yogibimbi Aug 11 '13 at 00:02
-1

This person solved your issue by installing DBD::mysql and DBI manually instead of via CPAN:

http://forums.mysql.com/read.php?51,281769,282127#msg-282127

srchulo
  • 5,143
  • 4
  • 43
  • 72
  • so what? :) The link doesn't have any information about how to actually do it. – Anton Babenko Nov 29 '14 at 13:38
  • @AntonBabenko so? It gives the answer on exactly what you need to do to solve it. Installing modules manually instead of using CPAN is a very common task. Knowing that's what you need to do, if you do not know how you can Google it. – srchulo Nov 30 '14 at 17:44
  • 1
    You could just write it instead of pointing to link. Anyway, thanks if your advice helped someone other than me. – Anton Babenko Nov 30 '14 at 18:43