Method One: Use the tee in the mysql> prompt
Mysql> Tee output.txt
Logging to file ' Output.txt '
Mysql> notee
Outfile disabled.
Or
mysql> \ Output.txt
Logging to file ' Output.txt '
mysql> \ t
Outfile disabled.
This spool function, similar to Sqlplus, allows you to save the results from the command line to an external file. If you specify a file that already exists, the result is appended to the file.
Method Two: Use the--tee parameter of the MySQL command line tool
$mysql--tee=ot.txt
Logging to file ' Ot.txt '
Mysql>
This will log all input and output contents to the specified file (until exit). If you specify a file that already exists, the result is appended to the file.
This article is from the "Programming Art" blog, so be sure to keep this source http://itsart.blog.51cto.com/1005243/1871169
Save the SQL run results in MySQL to a file