#! /usr/bin/perl
use DBI();
# Connect to the database
my $db="dbname";
my $host='dbhost'
my $user='dbuser';
my $password='passwd';
#my $query=shift;
my $dbh = DBI->connect("DBI:mysql:database=$db;host=$host",
$user, $password,
{RaiseError => 1})
|| die "Database connection not made: $DBI::errstr";
$sth = $dbh->prepare("select * from table where colunm='match-string'");
$dbh->do("SET character_set_client='utf8'");
$dbh->do("SET character_set_connection='utf8'");
$dbh->do("SET character_set_results='utf8'");
$sth->execute;
while ( @row = $sth->fetchrow_array() ) {
print "@row\n";
}
$sth->finish();
# Disconnect from the database.
$dbh->disconnect();
Ref:http://dev.mysql.com/doc/refman/5.0/en/charset-general.html