Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have sql files "separated" like this:

> tree sql
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
add comment

2 Answers 2

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
add comment

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
add comment

Your Answer

 
discard

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.