0

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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.