perl 链接mysql数据库 mac 系统

栏目: Perl · 发布时间: 7年前

内容简介: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

首发地址:月小升博客 –

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


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

软件测试经验与教训

软件测试经验与教训

Cem Kaner、James Bach、Bret Pettichord / 机械工业出版社 / 2004-1 / 35.00

本书汇总了293条来自软件测试界顶尖专家的经验与建议,阐述了如何做好测试工作、如何管理测试,以及如何澄清有关软件测试的常见误解,读者可直接将这些建议用于自己的测试项目工作中。这些经验中的每一条都是与软件测试有关的一个观点,观点后面是针对运用该测试经验的方法、时机和原因的解释或例子。 本书还提供了有关如何将本书提供的经验有选择性地运用到读者实际项目环境中的建议,在所有关键问题上所积累的经验,以......一起来看看 《软件测试经验与教训》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

MD5 加密
MD5 加密

MD5 加密工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具