perl 链接mysql数据库 mac 系统

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

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

首发地址:月小升博客 –

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


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

查看所有标签

猜你喜欢:

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

The Sovereign Individual

The Sovereign Individual

James Dale Davidson、William Rees-Mogg / Free Press / 1999-08-26 / USD 16.00

Two renowned investment advisors and authors of the bestseller The Great Reckoning bring to light both currents of disaster and the potential for prosperity and renewal in the face of radical changes ......一起来看看 《The Sovereign Individual》 这本书的介绍吧!

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

html转js在线工具
html转js在线工具

html转js在线工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换