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

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

SELECT INTO OUTFILE works in SELECTs, only, and tries to create files on the MySQL server. That won't work, I'm affraid.
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...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.