存档

文章标签 ‘Library not loaded: libmysqlclient.18.dylib’

MAC下安装DBD::mysql

2012年10月24日 没有评论

安装DBI没有问题

启动MySQL

localhost:~ daihu$ PATH=$PATH:/usr/local/mysql/bin
localhost:~ daihu$ mysqld_safe &
[1] 10778

localhost:~ daihu$ sudo perl -MCPAN -e shell
Password:
Terminal does not support AddHistory.

cpan shell — CPAN exploration and modules installation (v1.9456)
Enter ‘h’ for help.

cpan[1]>install DBI

可是到这一步就不行了

cpan[5]> install DBD::mysql
Running install for module ‘DBD::mysql’
Running make for C/CA/CAPTTOFU/DBD-mysql-4.022.tar.gz
Has already been unwrapped into directory /Users/daihu/.cpan/build/DBD-mysql-4.022-ZEmItw
Has already been made
Running make test
PERL_DL_NONLAZY=1 /usr/bin/perl “-MExtUtils::Command::MM” “-e” “test_harness(0, ‘blib/lib’, ‘blib/arch’)” t/*.t
t/00base.t ……………… 1/6 Bailout called. Further testing stopped: Unable to load DBD::mysql

# Failed test ‘use DBD::mysql;’
# at t/00base.t line 21.
# Tried to use ‘DBD::mysql’.
# Error: Can’t load ‘/Users/daihu/.cpan/build/DBD-mysql-4.022-ZEmItw/blib/arch/auto/DBD/mysql/mysql.bundle’ for module DBD::mysql: dlopen(/Users/daihu/.cpan/build/DBD-mysql-4.022-ZEmItw/blib/arch/auto/DBD/mysql/mysql.bundle, 2): Library not loaded: libmysqlclient.18.dylib
# Referenced from: /Users/daihu/.cpan/build/DBD-mysql-4.022-ZEmItw/blib/arch/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 7) line 2
# Compilation failed in require at (eval 7) line 2.
# BEGIN failed–compilation aborted at (eval 7) line 2.
FAILED–Further testing stopped: Unable to load DBD::mysql
make: *** [test_dynamic] Error 255
CAPTTOFU/DBD-mysql-4.022.tar.gz
/usr/bin/make test — NOT OK
//hint// to see the cpan-testers results for installing this module, try:
reports CAPTTOFU/DBD-mysql-4.022.tar.gz
Running make install
make test had returned bad status, won’t install without force
Failed during this command:
CAPTTOFU/DBD-mysql-4.022.tar.gz : make_test NO

cpan[6]>

解决:

localhost:lib daihu$ /usr/local/mysql/lib/
libmysqlclient.18.dylib libmysqlclient_r.dylib
libmysqlclient.dylib plugin/
libmysqlclient_r.18.dylib
localhost:lib daihu$ /usr/local/mysql/lib/

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

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mysql/lib/

localhost:lib daihu$ sudo ln -s libmysqlclient.18.dylib /usr/lib/ibmysqlclient.18.dylib


cpan[3]> install Bundle::CPAN
Fetching with LWP:
ftp://mirrors.xmu.edu.cn/CPAN/authors/id/A/AN/ANDK/Bundle-CPAN-1.861.tar.gz
Fetching with LWP:
ftp://mirrors.xmu.edu.cn/CPAN/authors/id/A/AN/ANDK/CHECKSUMS

cpan> reload cpan

cpan> install Bundle::LWP



更新一个源试下

cpan[3]> o conf urllist unshift http://mirrors.sohu.com/CPAN/
Please use ‘o conf commit’ to make the config permanent!

cpan[4]> o conf commit
commit: wrote ‘/Users/daihu/.cpan/CPAN/MyConfig.pm’

cpan[5]>

============================================================================================

# Failed test ‘use DBD::mysql;’
# at t/00base.t line 21.
# Tried to use ‘DBD::mysql’.
# Error: Can’t load ‘/Users/daihu/.cpan/build/DBD-mysql-4.022-6PSHtK/blib/arch/auto/DBD/mysql/mysql.bundle’ for module DBD::mysql: dlopen(/Users/daihu/.cpan/build/DBD-mysql-4.022-6PSHtK/blib/arch/auto/DBD/mysql/mysql.bundle, 2): Library not loaded: libmysqlclient.18.dylib
# Referenced from: /Users/daihu/.cpan/build/DBD-mysql-4.022-6PSHtK/blib/arch/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 7) line 2
# Compilation failed in require at (eval 7) line 2.
# BEGIN failed–compilation aborted at (eval 7) line 2.
FAILED–Further testing stopped: Unable to load DBD::mysql
make: *** [test_dynamic] Error 255
CAPTTOFU/DBD-mysql-4.022.tar.gz
/usr/bin/make test — NOT OK
//hint// to see the cpan-testers results for installing this module, try:
reports CAPTTOFU/DBD-mysql-4.022.tar.gz
Running make install
make test had returned bad status, won’t install without force
Failed during this command:
CAPTTOFU/DBD-mysql-4.022.tar.gz : make_test NO

 

 

shell> unset LANG
shell> perl Makefile.PL -mysql_config=/home/mysql/bin/mysql_config -testuser=root -testpassword=dbadmin
shell> make
shell> make test
一切正常,yeah!!!
我终于可以
shell> make install

 

总结
shell> unset LANG (若os的默认字符编码为UTF8,例如FCX)
shell> PATH=/home/mysql/bin:$PATH; export PATH (mysql的安装路径根据实际情况填写)
shell> perl -MCPAN -e shell
cpan> install DBI (根据自己需要)
cpan> force install DBD::mysql (忽略make test结果,强行安装)