linux down perl operation mysql database of requires the installation of DBI

  • 2020-05-13 03:35:00
  • OfStack

DBI installation: DBI details reference: http: / / dbi perl. org /
1. Download the DBI package:
wget http://search.cpan.org/CPAN/authors/id/T/TI/TIMB/DBI-1.620.tar.gz
2 decompression
tar xzf DBI-1.620.tar.gz
3 enter into the decompression package,
perl Makefile.PL
4 make test
5 make
6 make install (if not root user, sudo1)
DBD installation:
1. Download DBD
wget http://search.cpan.org/CPAN/authors/id/C/CA/CAPTTOFU/DBD-mysql-4.021.tar.gz
2. 3. Same as above
In step 3, it is possible that mysql_config could not be found and the development kit should not be installed
sudo apt-get install libmysqld-dev
sudo apt-get install libmysqlclient-dev
To install the two packages.
The rest is the same as above.
Once the installation is complete, you can manipulate the mysql data using the perl script.
Write perl scripts to manipulate the database
 
#! /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; 
#  Print the obtained data  
while(@recs=$sth->fetchrow_array){ 
print $recs[0].":".$recs[1]."\n"; 
} 
$sth->finish(); 
$dbh->disconnect(); 

Related articles: