Q:

Mysql from command line: execute sql code and then sql script

I want to execute some "sql code" and then sql script that uses mysql user defined variables that I set in the "sql code".
I try from the command line (bash):
mysql -e "sql code" < script.sql

but only "sql code" gets executed. Is there a neat way to accomplish that?

A:

Move things around with cat - and pipe.
echo "sql code" | cat - script.sql | mysql

The hyphen - tells cat to pass standard in to standard out and since its the first argument it'll wait until standard is finished before sending script.sql

