No MySQL você precisa usar os comandos
tee ¬ee :tee data.txt;
//SQL sentences...
notee;
tee data.txt ==spool data.txt notee ==spool off tee ¬ee :tee data.txt;
//SQL sentences...
notee;
tee data.txt ==spool data.txt notee ==spool off