I am trying to execute foo.sql using the source command in MySQL.
When I type the command, the file is sourced accordingly:
mysql> source ~/foo.sql
Use the command line:
mysql -p dbname < ~/foo.sql > ~/foo.txt
You could do it from the shell prompt:
$ mysql -p dbname < foo.sql > foo.txt
From within your MySQL client, type
tee session.out
From that point on, all the I/O of in your current client session is written to the file 'session.out'