You can use the INTO OUTFILE syntax in any SELECT query:
SELECT columnname
INTO OUTFILE 'output.txt'
FROM tablename
See
http://dev.mysql.com/doc/refman/5.0/en/select.html
Note that this creates a file on the host where MySQL Server is running, which is not necessarily the same host where your Perl script is running.
For what it's worth, you don't necessarily have to load all the data into memory when querying from Perl. You can use DBI to execute a query, and then loop over the rows of the result set. Your script would only store one row of the result set at any given time, during this loop. It would write the data to a file as it goes.
For example:
$sth = $dbh->prepare("SELECT foo FROM table");
$sth->execute();
open(TEXTFILE, ">output.txt") or die($!);
while (@row = $sth->fetchrow_array()) {
print TEXTFILE "@row\n";
}
close(TEXTFILE);
Regards,
Bill K.
Edited 1 time(s). Last edit at 05/25/2006 11:04AM by Bill Karwin.