0

When I run the following for the mysql> promt:

USE database;
TEE out.log;
UPDATE...query...

the result ends up in out.log as expected. However when running the following command from CLI:

mysql -u user -pSECRET --tee out.log database < query.sql

out.log comes up blank. I've also tried

mysql -u user -pSECRET database < query.sql > out.log

with the same result (blank file). I'm having a heck of a time figuring out why. What am I missing?

David
  • 68
  • 1
  • 7
  • possible duplicate of [Is there any way to log queries and output to a file?](http://stackoverflow.com/questions/23286004/is-there-any-way-to-log-queries-and-output-to-a-file) – Bill Karwin Apr 27 '14 at 18:52
  • Thanks Bill, but when I added the -v flag (per accepted answer at the link you mentioned) I'm now seeing the statement output to the screen, but not in the file. Also I'm not seeing the result in either the file, or on the screen – David Apr 27 '14 at 19:05
  • FYI here is what the updated query looked like: mysql -u user -pSECRET -v --tee out.log database < query.sql – David Apr 27 '14 at 19:07
  • mysql -u user -pSECRET -v database < query.sql > out.log logs statement but no result either – David Apr 27 '14 at 19:10
  • I have added an explanation that it doesn't work in interactive mode in the answer I linked to. – Bill Karwin Apr 27 '14 at 19:35

1 Answers1

0

For anyone else with this issue, here's what finally worked for me:

Put the following in a shell script:

#!/bin/bash
for file in *.sql
do
  mysql -u user -pSECRET -v database < $file
done

Then run the script with

sh run.sh > logfile 2>&1

This runs all my queries, and shows the

Query OK, xx rows affected;

or whatever errors come up in my logfile. Hope this saves the next guy a few hours.

David
  • 68
  • 1
  • 7