Saturday, April 27, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1083  / 3 Years ago, sat, may 1, 2021, 2:32:00

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?


More From » files

 Answers
3

Here's my solution:



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

[#38878] Sunday, May 2, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
armis

Total Points: 38
Total Questions: 106
Total Answers: 118

Location: Mali
Member since Sat, Feb 12, 2022
2 Years ago
;