Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql pipe tee buffers output

Tags:

mysql

pipe

When I run the mysql command line tool in non interactive mode and just watch the results, I see them as each query is executed. But if I pipe it to "tee", mysql is buffering the results and I only see it all af the end. How can I instruct mysql to output the results right away? I already tried "-q" to no success, I can't find the right option in the help page. :(

Example: query_dates.txt contains 200 queries each taking about 30 seconds.

head -4 query_dates.txt | mysql -u tester -h 172.16.77.30 myDB -ss
2015-05-01      375398346
2015-05-02      375704957
2015-05-03      375992591
2015-05-04      376193384

In this case, I see each line every 30 seconds, across 2 minutes.

head -4 query_dates.txt | mysql -u tester -h 172.16.77.30 myDB -ss | tee 001.date_itemid.txt
2015-05-01      375398346
2015-05-02      375704957
2015-05-03      375992591
2015-05-04      376193384

In this case, I have to wait 2 minutes and at the end I get the 4 results.

P.S.: I found this and using stdbuf in mysql worked, but I still would like to know which mysql option does the trick... if any.

like image 681
msb Avatar asked Oct 18 '25 10:10

msb


1 Answers

From the man page:

  • --unbuffered, -n
    Flush the buffer after each query.
like image 154
Barmar Avatar answered Oct 22 '25 08:10

Barmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!