使用dbi,如果linux中没有,则需要安装
#!/bin/perl
# load module
use DBI;
my $db="mydb";
my $host='localhost';
my $user='myuser;
my $password='mypassword';
# connect
my $dbh = DBI->connect("DBI:mysql:database=$db;host=$host", $user, $password, {RaiseError => 1});
$sql="SELECT IP FROM mydb where ip<>'' GROUP BY IP HAVING Count(IP)>1";
# rows
$sth = $dbh->prepare($sql);
# my $rows = $dbh->do($sql);
$sth->execute();
while(@ip=$sth->fetchrow_array())
#如果使用需要把数组中包含的多字段分隔,使用(($filed1,$field2,……,$filedn)=$sth->fetchrow_array()),会自动把获取的字段值赋给变量
{
$sql1="update radcheck set ip='' where ip='".$ip."'";
print "sql1:".$sql1."/n";
$dbh->do($sql); #直接执行无返回值命令使用->do
}
$dbh->disconnect();