Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a number of sql files to import. For a single file I use the following command:

mysql -u root -p dbname < db.sql

Is it possible to use xargs to bulk import all files? something like: ls *.sql | xargs ....

I know that mysqlimport is the solution but I want to know if it's possible with xargs or not.

share|improve this question
up vote 4 down vote accepted

xargs is suitable to transform input into command line parameters. But as mysql not accepts SQL script file name parameter, xargs is not handy in this case.

This is a useful use of cat:

cat *.sql | mysql -u root -p dbname

Anyway, your attempt to use ls in that way leads to the famous Why you shouldn't parse the output of ls(1) article.

share|improve this answer
Con cat enation, who knew! – jordanm Oct 23 '12 at 21:19

If your sql files are independent of eachother it may be faster to import them in parallel:

parallel -j10 sql mysql://root:passwd@/dbname '<' {} ::: *.sql

Watch the intro video to GNU Parallel to learn more: https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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