Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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 bunch of .sql files in a directory that I need to import. Although I can do it manually, for scripting purposes I need to be able to apply them in bulk. How can I do that though? What combination of options and commands do I need?

The mysqlimport command goes like this:

mysqlimport [options] db_name textfile1 [textfile2 ...]

I need to be able to add all the text files to the end. I would prefer a command than a convoluted for loop if possible.

Any suggestions?

share|improve this question
up vote 6 down vote accepted

Use wildcards:

mysqlimport [options] db_name /path/to/sql/files/*

If there are non-SQL files in that directory, the subset of files you do want to import may have some part of their file name in common. For instance, if they all end in .sql, the command becomes:

mysqlimport [options] db_name /path/to/sql/files/*.sql

If you come from DOS/Windows, it may not be clear to you why this works. On Unixy systems, the shell expands wildcards, so the program (mysqlimport in this case) doesn't have to have its own processing. That's why the usage message you quote says it expects the files to be given individually: that's how it will see the files if you use commands like the above. The program only sees the wildcard if the pattern doesn't match anything; the shell passes it on literally to the program, having no better way of handling it.

share|improve this answer
So Bash will expand the wildcard to a list of all the matching files? – TheLQ Dec 10 '10 at 22:42
Yes. To see this yourself, try this old hack for working around a broken/missing ls command: echo /path/to/sql/files/*.sql – Warren Young Dec 10 '10 at 23:21
Nice, this works perfectly! Thanks for pointing this out. I have no idea bash did this – TheLQ Dec 10 '10 at 23:41

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.