perl DBD :: mysql不能用于mysql 5.6?

时间:2013-03-08 04:55:44

标签: mysql perl osx-mountain-lion dbi perlbrew

我在Mac OSX 10.8.2上安装了MySQL 5.6.10,位于/usr/local/mysql-5.6.10-osx10.7-x86_64/。然后我尝试运行一个使用DBI和DBD :: mysql连接到MySQL数据库的Perl程序。我收到了以下错误:

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

(当我使用'brew'(与perlbrew无关)将mysql 5.5安装到自己的目录/ usr / local / Cellar /中时,这很好用。由于brew还不知道5.6,我安装了它手动。)

我能够从mysql命令行启动mysqld并成功连接。此错误是否表明Perl的DBD :: mysql模块存在问题?它是最新的;也许它无法与MySqL 5.6交谈?

谢谢!

2 个答案:

答案 0 :(得分:1)

我在Mac上安装DBD :: mysql时遇到了一些问题,我发现以下内容可以解决 带有Perl 5.16.1和MySQL 5.5.27的Mac OSX 10.6.8,其中mysql安装在/ usr / local /中。 请仔细检查以下命令中使用的任何路径和用户名。

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

然后检查连接(假设您仍然拥有测试数据库并启用了匿名用户)

perl -e "use DBD::mysql; my $dbh = DBI->connect('dbi:mysql:test:localhost::3306:mysql_socket=/tmp/mysql.sock'); $dbh->disconnect();"

答案 1 :(得分:0)

此人通过手动安装DBD :: mysql和DBI而不是通过CPAN解决了您的问题:

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