wget http://www.cpan.org/modules/by-module/DBI/DBI-1.623.tar.gz
tar -zxvf DBI-1.623.tar.gz
cd DBI-1.623
perl Makefile.PL
make
make install
wget http://www.cpan.org/modules/by-module/DBD/DBD-mysql-4.022.tar.gz
tar zxf DBD-mysql-4.022.tar.gz
cd DBD-mysql-4.022
perl Makefile.PL --mysql_config=/usr/local/mysql/bin/mysql_config
make && make install
案例: 连接数据库
#!/usr/bin/perl
use strict;
use DBI;
my $dbname="mysql";
my $location="127.0.0.1";
my $port="3306";
my $database="DBI:mysql:$dbname:$location:$port";
my $dbh = DBI->connect($database,"root","123456");
my $sth = $dbh->prepare ("select host from mysql.user");
$sth->execute();
while (my @row = $sth->fetchrow_array()) {
print "=====> @row <=========\n";
}
$sth->finish();
tar -zxvf DBI-1.623.tar.gz
cd DBI-1.623
perl Makefile.PL
make
make install
wget http://www.cpan.org/modules/by-module/DBD/DBD-mysql-4.022.tar.gz
tar zxf DBD-mysql-4.022.tar.gz
cd DBD-mysql-4.022
perl Makefile.PL --mysql_config=/usr/local/mysql/bin/mysql_config
make && make install
案例: 连接数据库
#!/usr/bin/perl
use strict;
use DBI;
my $dbname="mysql";
my $location="127.0.0.1";
my $port="3306";
my $database="DBI:mysql:$dbname:$location:$port";
my $dbh = DBI->connect($database,"root","123456");
my $sth = $dbh->prepare ("select host from mysql.user");
$sth->execute();
while (my @row = $sth->fetchrow_array()) {
print "=====> @row <=========\n";
}
$sth->finish();
$dbh->disconnect();
本文转自cloves 51CTO博客,原文链接:http://blog.51cto.com/yeqing/1738651