返回
前端
分类

DBI和DBD-mysql模块的安装

日期: 2020-01-02 08:00 浏览次数 : 140

DBI和DBD-mysql模块的安装

DBI安装:DBI详细信息参考: 1.下载DBI包: wget 2 解压 tar xzf DBI-1.620.tar.gz 3 进入解压包内, perl Makefile.PL 4 make test 5 make 6 make install DBD安装: 1.下载DBD wget

 

    1. 同上 在进行第三步是可能会出现mysql_config找不到的情况,应该是没有安装开发工具包 sudo apt-get install libmysqld-dev sudo apt-get install libmysqlclient-dev 来安装这两个包。 其余同上。 完成安装后就可以利用perl脚本进行mysql数据的操作了。 编写perl脚本操作数据库 复制代码 代码如下: #! /usr/bin/perl use DBI; my $driver="DBI:mysql"; my $database="perl_test"; my $user="root"; my $host="localhost"; my $passwd="root"; my $rules="alert_rules"; my $dbh = DBI->connect("$driver:database=$database;host=$host;user=$user;password=$passwd") or die "Can't connect: " . DBI->errstr; my $sth=$dbh->prepare("select app_name,receivers from $rules "); $sth->execute() or die "Can't prepare sql statement". $sth->errstr; my $sth=$dbh->prepare("select app_name,receivers from $rules "); $sth->execute() or die "Can't prepare sql statement". $sth->errstr; # 打印获取的数据 while(@recs=$sth->fetchrow_array){ print $recs[0].":".$recs[1]."n"; } $sth->finish;

必赢备用网址 ,一、DBI的安装

wget

tar -zxvf DBI-1.604.tar.gz

cd DBI-1.604

perl Makefile.PL

make

make test

make install

 

二、DBD的安装 

yum -y intall  mysql-devel

注意mysql的环境变量,若没有则用 添加/usr/binl/mysql到环境变量PATH中 

PATH/usr/binl/mysql:$PATH;

export PATH (mysql的安装路径根据实际情况填写) 

 

wget

tar -zxvf DBD-mysql-4.006.tar.gz

cd DBD-mysql-4.006

perl Makefile.PL --mysql_config=/usr/bin/mysql_config

make

make test

make install

 

测试连接:

#!/usr/bin/perl

use DBI;

$user="test";

$passwd="test";

$dbh="";

$dbh = DBI->connect("dbi:mysql:database=test;host=192.1.1.168;port=3306",$user,$passwd) or die "can't connect to

database ". DBI-errstr;

$sth=$dbh->prepare("select * from infobright_loaddata_status");

$sth->execute;

while (@recs=$sth->fetchrow_array) {

print $recs[0].":".$recs[1].":".$recs[2]."n";

}

$dbh->disconnect;

一、DBI的安装 wget tar -zxvf DBI-1.604.tar.gz cd DBI-1.604 perl Makefile.PL make make...