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 >
You could do it from the shell prompt:
$ mysql -p dbname < foo.sql > foo.txt