You could use a 'here document'.
From man bash:
This type of redirection instructs the shell to read input from the current source until a line containing only word (with no trailing blanks) is seen. All of the lines read up to that point are then used as the standard input for a command.
<some other code>
From within the script mysql is started and everything between the first and the last EOF is given to mysql and executed by mysql.
Example (sqlplus, but principle is the same):
sqlplus -silent <<SQLscript
set linesize 122
set pagesize 0
set heading off
from smf_user u, smf_user_access a, smf_template t
order by t.template , u.description
Hope this gets you going again.