0

I'd like to execute a SQL script file from mysql command line tool, like

mysql database < script.sql

where the script script.sql contains a statement that redirects the output to a file.

I thought this should be possible by placing a tee into the script like this:

tee script.log;

SELECT sysdate() AS "Start" FROM dual;
UPDATE table SET column = 'off';
COMMIT;

Unfortunately, this does not work, no script.log appears.

Is there any possibility to redirect the output to a file from the script itself?

Use case: These scripts will be executed by our Service Department when deploying the application. They would like to execute the script with as little steps and effort as possible, so placing a redirect (> script.log) at the end of the command prompt is not a real option, at least if they must execute a bunch of scripts at once.

Thanks in advance, Michael

Michael
  • 291
  • 1
  • 3
  • 13

1 Answers1

0

Use OUTFILE as part of SELECT itself as follows: SELECT * FROM myTable INTO OUTFILE '/path/to/file.log'. Also, for spoolong, check What is the equivalent of the spool command in mysql

Community
  • 1
  • 1
rags
  • 2,580
  • 19
  • 37
  • `SELECT INTO OUTFILE` works in SELECTs, only, and tries to create files on the MySQL server. That won't work, I'm affraid. – Michael Jan 11 '13 at 12:26
  • Thanks for the link, that's the usual solution, but doesn't fit into use case. Anyway, I guess I have to provide a thin wrapper scipt to Sevice Dep... – Michael Jan 14 '13 at 08:28