linux下将mysql数据导入到CSV文件中,在windows下打开CSV文件中文为乱码
#!/usr/bin/perl
use utf8;
use DBI;
use Text::CSV_XS;
my ($dsn) = "DBI:mysql:extmail:localhost";
my ($user_name) = "root";
my ($password) = "123456";
my ($dbh, $sth);
$dbh = DBI->connect ($dsn, $user_name, $password, { RaiseError => 1 });
$sth = $dbh->prepare ("SELECT name, username FROM mailbox");
$sth->execute();
my $csv = Text::CSV_XS->new ({ binary => 1, eol => $/ });
open my $fh, ">", "tbl.csv" or die "$tbl.csv: $!";
$csv->print ($fh, $sth->{NAME_lc});
while (my $row = $sth->fetch) {
$csv->print ($fh, $row) or $csv->error_diag;
}
close $fh or die "tbl.csv: $!";
-----------------------------------------------------------------------------------------
以上是脚本代码,请高手帮帮忙。 谢谢!
use utf8;
use DBI;
use Text::CSV_XS;
my ($dsn) = "DBI:mysql:extmail:localhost";
my ($user_name) = "root";
my ($password) = "123456";
my ($dbh, $sth);
$dbh = DBI->connect ($dsn, $user_name, $password, { RaiseError => 1 });
$sth = $dbh->prepare ("SELECT name, username FROM mailbox");
$sth->execute();
my $csv = Text::CSV_XS->new ({ binary => 1, eol => $/ });
open my $fh, ">", "tbl.csv" or die "$tbl.csv: $!";
$csv->print ($fh, $sth->{NAME_lc});
while (my $row = $sth->fetch) {
$csv->print ($fh, $row) or $csv->error_diag;
}
close $fh or die "tbl.csv: $!";
-----------------------------------------------------------------------------------------
以上是脚本代码,请高手帮帮忙。 谢谢!
作者: 一介村管 发布时间: 2011-06-06
用DBD::mysql把数据读成“,”分割的文件就是了
不需要转编码格式,windows的notepad就能看utf8的内容
不需要转编码格式,windows的notepad就能看utf8的内容
作者: py 发布时间: 2011-06-06