I have a file created with mysqldump that is 11GB. I need to use the "mysql" command to import it into a database, but I need to add:

USE db1;

at the top. It would take forever to rewrite the file. Is there a way I can concatenate another file at the beginning of the input redirect to fool it into looking at it as a single file?

text.txt contents:

USE db1;

sql_out.sql contents:

data from mysqldump using the --skip-add-drop-table and --no-create-info options

command attempted:

mysql --host=<host> --user=<user> --password=<pwd> < echo $(cat text.txt sql_out.sql)

When I do that I get:

echo: No such file or directory

If I try it without the echo, I get:

$(cat text.txt sql_out.sql): ambiguous redirect

Is there a way to do this?

  • If I understand the question correctly, you could just use the -D db1 option to mysql, and redirect the contents of the sql file to the mysql command without even using cat. Ex:mysql -host foo.io -u -p1234 yoda -D db1 < sql_out.sql Apr 8, 2018 at 10:09

2 Answers 2


You can pipe it in:

cat text.txt sql_out.sql | mysql --host=...

Alternatively, to avoid having to create a new file:

(echo "USE db1;"; cat sql_out.sql) | mysql --host=...

You could use process substitution here:

mysql --host=<host> --user=<user> --password=<pwd> < <(cat text.txt sql_out.sql)

the syntax <(...) treats a process's like a file

  • That is an interesting way of doing it. Thank you!
    – raphael75
    Mar 21, 2017 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.