use strict; use warnings; use DBI; use DBD::mysql; my $DB='database'; my $HOST='remote_host_ip_address'; my $user='user_name'; my $pass='password'; my $table='table_to_be_dumped'; my $file_to_be_written_to="c:/temp/output.txt"; # Connect to database. my $dbh=DBI->connect( "DBI:mysql:database=$DB;host=$HOST;", $user, $pass) or die "$!\n"; my $sth=$dbh->prepare("SELECT * FROM $table") or die "$!\n"; $sth->execute(); open(FH, ">$file_to_be_written_to") or die "$!\n"; while (my @row=$sth->fetchrow_array()) { print FH join(",", @row)."\n"; } close FH; $sth->finish(); $dbh->disconnect();