perl 解決mysql utf8中文亂碼 問題。
mysql utf8 中文問題:
zabbix:/root/sbin# cat a1.pl
use dbi;
my $dbuser='devops';
my $user="root";
my $passwd="kjk123123";
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中文亂碼
@arr2=();
#$dbh->do("set names utf8");
my $hostsql = qq;
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\n";
print "11111111111111111\n";
while( $selstmt->fetch() )
;print @arr2;
此時亂碼
zabbix:/root/sbin# perl a1.pl
,,11111111111111111
192.168.11.134 bi????????? esx-192.168.4.41
192.168.11.106 ????????? esx-192.168.4.41
192.168.10.163 ?????1???? esx-192.168.4.41
192.168.10.164 ?????2???? esx-192.168.4.41
192.168.10.107 bj-nginx esx-192.168.4.41
192.168.10.161 ????app????? esx-192.168.4.41
192.168.10.162 ????db????? esx-192.168.4.41
192.168.10.145 ??-????????? esx-192.168.4.41
192.168.10.132 ?pms??db???? esx-192.168.4.41
192.168.10.223 pms-luopan2???? esx-192.168.4.41
192.168.10.241 yunying-app????? esx-192.168.4.41
192.168.10.242 yunying-db????? esx-192.168.4.41
192.168.11.157 ntp1 esx-192.168.4.41
192.168.11.158 ntp2 esx-192.168.4.41
192.168.11.161 liuyanqiang-test esx-192.168.4.41
192.168.10.52 nc??????? esx-192.168.4.41
192.168.10.51 nc??????? esx-192.168.4.41
192.168.10.53 nc???????? esx-192.168.4.41
開啟utf8:
$dbh->do("set names utf8");
zabbix:/root/sbin# perl a1.pl
,,11111111111111111
192.168.11.134 bi遠端配置(何易澤) esx-192.168.4.41
192.168.11.106 北京測試機(北京) esx-192.168.4.41
192.168.10.163 拓購巨省心1(北京) esx-192.168.4.41
192.168.10.164 拓購巨省心2(北京) esx-192.168.4.41
192.168.10.107 bj-nginx esx-192.168.4.41
192.168.10.161 智控**app(楊晶鵬) esx-192.168.4.41
192.168.10.162 智控**db(楊晶鵬) esx-192.168.4.41
192.168.10.145 智控-拓購專用(楊晶鵬) esx-192.168.4.41
192.168.10.132 新pms培訓db(沈波) esx-192.168.4.41
192.168.10.223 pms-luopan2(沈波) esx-192.168.4.41
192.168.10.241 yunying-app(楊晶鵬) esx-192.168.4.41
192.168.10.242 yunying-db(楊晶鵬) esx-192.168.4.41
192.168.11.157 ntp1 esx-192.168.4.41
192.168.11.158 ntp2 esx-192.168.4.41
192.168.11.161 liuyanqiang-test esx-192.168.4.41
192.168.10.52 nc人事應用伺服器 esx-192.168.4.41
192.168.10.51 nc財務應用伺服器 esx-192.168.4.41
192.168.10.53 nc財務資料庫伺服器 esx-192.168.4.41
或者:zabbix:/root/sbin# cat a1.pl
use dbi;
use encode;
my $dbuser='devops';
my $user="root";
my $passwd="kjk123123";
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中文亂碼
@arr2=();
#$dbh->do("set names utf8");
my $hostsql = qq;
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\n";
print "11111111111111111\n";
while( $selstmt->fetch() )
;print @arr2;
zabbix:/root/sbin# perl a1.pl
,,11111111111111111
192.168.11.134 bi遠端配置(何易澤) esx-192.168.4.41
192.168.11.106 北京測試機(北京) esx-192.168.4.41
192.168.10.163 拓購巨省心1(北京) esx-192.168.4.41
192.168.10.164 拓購巨省心2(北京) esx-192.168.4.41
192.168.10.107 bj-nginx esx-192.168.4.41
192.168.10.161 智控**app(楊晶鵬) esx-192.168.4.41
192.168.10.162 智控**db(楊晶鵬) esx-192.168.4.41
192.168.10.145 智控-拓購專用(楊晶鵬) esx-192.168.4.41
192.168.10.132 新pms培訓db(沈波) esx-192.168.4.41
192.168.10.223 pms-luopan2(沈波) esx-192.168.4.41
192.168.10.241 yunying-app(楊晶鵬) esx-192.168.4.41
192.168.10.242 yunying-db(楊晶鵬) esx-192.168.4.41
192.168.11.157 ntp1 esx-192.168.4.41
192.168.11.158 ntp2 esx-192.168.4.41
192.168.11.161 liuyanqiang-test esx-192.168.4.41
192.168.10.52 nc人事應用伺服器 esx-192.168.4.41
192.168.10.51 nc財務應用伺服器 esx-192.168.4.41
192.168.10.53 nc財務資料庫伺服器 esx-192.168.4.41
mysql utf8設定 mysql設定utf 8
mysql編碼為utf8設定方法 一 編輯mysql的配置檔案 vim etc my.cnf 在 mysqld 標籤下加上三行 default character set utf8 character set server utf8 在 mysql 標籤下加上一行 default character...
MySQL UTF8 中文亂碼處理
mysql安裝好後預設字符集不是utf8,因此顯示中文會有問題。在mysql可以執行 show variables like character 檢視當前字符集使用的編碼方式,如 以mysql 5.5版為例,在mysql安裝目錄下的my.ini 增加 mysql default character ...
Mysql utf8 和utf8mb4 的區別
mysql 批量更改資料表和字段的字符集 mysql utf 8字符集更改為utf8mb4字符集 我們新建mysql資料庫的時候,需要指定資料庫的字符集,一般我們都是選擇utf8這個字符集,但是還會又乙個utf8mb4這個字符集,好像和utf8有聯絡,今天就來解析一下這兩者的區別。mysql在5.5...