Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 sql files "separated" like this:

> tree sql
├── adresse_trigger_update_before.sql
├── attribut_trigger_update_before.sql
├── categorie_trigger_update_before.sql
├── duplicate_records.sql
├── horaire_trigger_update_before.sql
├── partenaire_trigger_update_before.sql
├── personne_trigger_update_before.sql
└── produit_trigger_update_before.sql

0 directories, 8 files

Here are all my tries:

>mysql mydatabase -e "source sql/file1.sql"
>mysql mydatabase -e "source sql/*"
>ERROR at line 1: Failed to open file 'sql/*', error: 2
>cat sql/* > mysql mydatabase
>cat : option invalid -- 'p'
>mysql mydatabase -e "source sql/*"
>bash: sql/* : ambiguous redirect

How to load many files at once in MySQL?

Nota: there's only one problem I'm facing: load all the files in the "sql" folder at once. No other problem (I've removed user and password to be more precise about the actual problem).

Any idea how to do this?

share|improve this question
up vote 1 down vote accepted

Here's my solution:

find sql/ -type f | awk '{system("mysql -u root -pXXX -h localhost mydatabase < "$0)}'
share|improve this answer

You should use "source code"/* instead.

For the password issue , try quote it , e.g mysql -u XX -p "XX"

share|improve this answer
Hi, I have no password issue. I may not be clear enough, I've updated my question. I hope this is clearer now. – Olivier Pons May 1 '12 at 9:29

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.