MySQL tee out.log works from client, but coming up

2019-08-23 22:49发布

问题:

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?

回答1:

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.



标签: mysql tee