中文乱码 $dbh->do("SET NAMES utf8");

use DBI;
my $dbUser='DEVOPS';
my $user="root";
my $passwd="kjk123123";
my @arr2="";
my $dbh  = DBI->connect("dbi:mysql:database=DEVOPS;host=192.168.11.185;port=3306",$user,$passwd) or die "can't connect to database ". DBI-errstr;
##防止utf-8中文乱码
$dbh->do("SET NAMES utf8");
my $hostSql = qq{select  IP,INFO,ENV from  machine_info  where ENV='$gp' };
my ($a1, $a2, $a3,$a4,$a5,$a6,$a7,$a8,$a9);
my $selStmt = $dbh->prepare($hostSql);
$selStmt->execute();
$selStmt->bind_columns(undef, $a1, $a2, $a3);
print "$a1|$a2,$a3
";
 while( $selStmt->fetch() )
 { push (@arr2, "$a1  $a2  $a3
" );
 };
$msg->reply("@arr2")}

原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6199048.html