rapt
rapt

Reputation: 12240

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?

Upvotes: 0

Views: 92

Answers (1)

Dan S
Dan S

Reputation: 9189

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

Upvotes: 1

Related Questions