mac perl dbd mysql_perl 链接mysql数据库 mac 系统

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

首发地址:月小升博客 –

无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值