perl 安装 DBI及 DBD-mysql

1、 DBI下载地址:
https://cpan.metacpan.org/authors/id/T/TI/TIMB/DBI-1.636.tar.gz

1.1 解压,编译:

tar -zxvf DBI-1.636.tar.gz
cd DBI-1.636
perl Makefile.PL
make
make test
make install

 

2. DBD-mysql下载地址
http://search.cpan.org/CPAN/authors/id/C/CA/CAPTTOFU/DBD-mysql-4.038.tar.gz

2.1 解压,编译:

tar -zxvf DBD-mysql-4.038.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

 1 #测试是否成功:
 2 #!/usr/bin/perl
 3 
 4 use DBI;
 5 $user="root";
 6 $passwd='xxxxxx';
 7 $dbh="";
 8 $dbh = DBI->connect("dbi:mysql:database=xxxx;host=xxxx;port=3309",$user,$passwd) or die "can't connect todatabase ". DBI-errstr;
 9 $sth=$dbh->prepare("select * from t_test_table limit 2");
10 $sth->execute;
11 while (@recs=$sth->fetchrow_array) {
12         print $recs[0].":".$recs[1].":".$recs[2]."\n";
13 }
14 $dbh->disconnect;
View Code

 

posted @ 2016-11-15 21:00  幸运的萤火虫  阅读(9333)  评论(0编辑  收藏  举报