一、DBI的安装
wget http://www.cpan.org/modules/by-module/DBD/DBI-1.604.tar.gz
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 http://www.cpan.org/modules/by-module/DBD/DBD-mysql-4.006.tar.gz
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/perluse 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 todatabase ". 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;