DBI和DBD-mysql模塊的安裝 一、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/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;