List:General Discussion« Previous MessageNext Message »
From:Gavin Towey Date:May 15 2009 12:01am
Subject:RE: Select Into OUTFILE problem
View as plain text  
Hi Bruce,

SELECT ... INTO OUTFILE always creates the file local to the database server.  If you want
to dump results where your perl script is running you'll have to use another method such
as receiving the results of the query normally and writing the file in the perl script.


Gavin Towey

I have a bit of perl code that ends with an error:

$sql="SELECT convert_tz( a.stamp,'GMT','$tz' ) as ts, a.status,


      INTO OUTFILE  '/application/result.csv'


      ENCLOSED BY '\"'


      FROM alerts a

      WHERE a.stamp BETWEEN ? AND ?

      ORDER BY a.stamp DESC";

 $sth = $dbh->prepare($sql);

 $rv = $sth->execute;

DBD::mysql::st execute failed: Can't create/write to file

'/application/result.csv' (Errcode: 2)

Te database is remote from the system where the perl is executing.

Te SQL works as expected when fed to mysql command line client

(i.e. mysql -h remote).  The outfile ends up in the application

directory of the macine running the mysql client.

What I'd found is, when the perl code runs the file tries to drop on the

database server and the application directory doesn't exist there giving

me the error.

Any suggestions to get the outfile to drop in the right place would be



The information contained in this transmission may contain privileged and confidential
information. It is intended only for the use of the person(s) named above. If you are not
the intended recipient, you are hereby notified that any review, dissemination,
distribution or duplication of this communication is strictly prohibited. If you are not
the intended recipient, please contact the sender by reply email and destroy all copies of
the original message.

Select Into OUTFILE problemBruce Ferrell13 May
RE: Select Into OUTFILE problemGavin Towey15 May
  • Re: Select Into OUTFILE problemBruce Ferrell15 May