内容简介:perl -vmac 系统自带安装mysql
perl -v
mac 系统自带
安装mysql
DBI
use strict;
use DBI;
my $host = "localhost"; # 主机地址
my $driver = "mysql"; # 接口类型 默认为 localhost
my $database = "crm"; # 数据库
# 驱动程序对象的句柄
my $dsn = "DBI:$driver:database=$database:$host";
my $userid = "urldb"; # 数据库用户名
my $password = "123456"; # 数据库密码
# 连接数据库
my $dbh = DBI->connect($dsn, $userid, $password ) or die $DBI::errstr;
my $sth = $dbh->prepare("SELECT * FROM fish_cash"); # 预处理 SQL 语句
$sth->execute(); # 执行 SQL 操作
# 注释这部分使用的是绑定值操作
# $alexa = 20;
# my $sth = $dbh->prepare("SELECT name, url
# FROM Websites
# WHERE alexa > ?");
# $sth->execute( $alexa ) or die $DBI::errstr;
# 循环输出所有数据
while ( my @row = $sth->fetchrow_array() )
{
print join('\t', @row)."\n";
}
$sth->finish();
$dbh->disconnect();
安装完毕,执行依然不行
Mac下配置 perl 的DBD::MySQL模块
perl -MCPAN -e shell
install模块
终端依次输入 自动命令行
perl -MCPAN -e shell
cpan[1]> install DBD::mysql
cpan[2]> exit
export DYLD_LIBRARY_PATH=”/usr/local/mysql/lib:$DYLD_LIBRARY_PATH”
/Applications/XAMPP/xamppfiles/lib/mysql/plugin/
find ./ -iname ‘mysqlclient’
export DYLD_LIBRARY_PATH=”/Applications/XAMPP/xamppfiles/bin:$DYLD_LIBRARY_PATH”
我的机器一直用XAMPP的 mysql 发现是个负担,很多教程都直接用usr/local/bin的mysql
比较容易
/Applications/XAMPP/xamppfiles/bin
/Applications/XAMPP/xamppfiles/bin/mysql_config
perl Makefile.PL –mysql_config=/Applications/XAMPP/xamppfiles/bin/mysql_config
perl Makefile.PL -mysql_config=/Applications/XAMPP/xamppfiles/bin/mysql_config -testuser=root -testpassword=dbadmin
perl -MCPAN -e “install DBD::mysql”
You can also optionally set the user to run ‘make test’ with:
perl Makefile.PL –testuser=username
Can’t exec “mysql_config”: No such file or directory at Makefile.PL line 561.
Can’t find mysql_config. Use –mysql_config option to specify where mysql_config is located
Failed to determine directory of mysql.h. Use
因为我的mysql在xampp下
make test perl Makefile.PL –testuser=username
无功劳
这个方案是最后成功了的方案
下载这个玩意
http://search.cpan.org/CPAN/authors/id/C/CA/CAPTTOFU/DBD-mysql-4.038.tar.gz
perl Makefile.PL –mysql_config=/Applications/XAMPP/xamppfiles/bin/mysql_config –testuser=urldb
perl Makefile.PL –mysql_config=/Applications/XAMPP/xamppfiles/bin/mysql_config –testuser=urldb –testpassword=123456
install_driver(mysql) failed: Can’t load ‘/Library/Perl/5.18/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle’ for module DBD::mysql: dlopen(/Library/Perl/5.18/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle, 1): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Library/Perl/5.18/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle
Reason: unsafe use of relative rpath libmysqlclient.18.dylib in /Library/Perl/5.18/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle with restricted binary at /System/Library/Perl/5.18/darwin-thread-multi-2level/DynaLoader.pm line 194.
找到个这个文件
/Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib /Library/Perl/5.18/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle
改成我自己的
otool -L /Library/Perl/5.18/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle
sudo install_name_tool -change libmysqlclient.18.dylib /Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib /Library/Perl/5.18/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle
好了。
如果你是一名技术人员可加我QQ 2651-0442-02,如果你是 java 技术人还可以加入QQ群 1784-9136-0
首发地址:月小升博客 –无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
程序员成长的烦恼
吴亮、周金桥、李春雷、周礼 / 华中科技大学出版社 / 2011-4 / 28.00元
还在犹豫该不该转行学编程?还在编程的道路上摸爬滚打?在追寻梦想的道路上你并不孤单,《程序员成长的烦恼》中的四位“草根”程序员也曾有过类似的困惑。看看油田焊接技术员出身的周金桥是如何成功转行当上程序员的,做过钳工、当过外贸跟单员的李春雷是如何自学编程的,打小在486计算机上学习编程的吴亮是如何一路坚持下来的,工作中屡屡受挫、频繁跳槽的周礼是如何找到出路的。 《程序员成长的烦恼》记录了他们一步一......一起来看看 《程序员成长的烦恼》 这本书的介绍吧!
Base64 编码/解码
Base64 编码/解码
RGB CMYK 转换工具
RGB CMYK 互转工具