TEE statement in mysql
The TEE statement may be used to log output from your SQL statements to a text file. The following command copies all output to the file query.txt so you can examine the results of running your queries.
mysql> TEE query.txt
You can turn off logging using the NOTEE statement.